Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Runtime error from same-line commands?

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
pjc30943



Joined: 02 Dec 2005
Posts: 220

Posted: 13 October 2009, 0:02 AM    Post subject: Runtime error from same-line commands? Reply with quote

My impression was that two or more lines of code can be inserted on the same line, like so:

Code:
CodeA : CodeB : CodeC


However, when CodeA is a subroutine, it fails to execute, and CodeB is the first thing run. Here's an example, where x and a are bytes, and subA is a short subroutine.

Code:
subA : x = a


This does NOT work, as subA is never called, but 'x' is correctly set to 'a'. But this configuration does work, of course:

Code:
subA
x = a


Thoughts? This is merely a readability issue, but if no error is thrown then it seems that all commands should run in both configurations.
Back to top
GTBecker



Joined: 18 Jan 2006
Posts: 457
Location: Cape Coral

Posted: 13 October 2009, 0:15 AM    Post subject: Reply with quote

SubA: is interpreted as a label?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 13 October 2009, 1:49 AM    Post subject: Reply with quote

GTBecker wrote:
SubA: is interpreted as a label?
Quite so. An identifier at the beginning of a line followed by a colon is taken to be a label. You can work around this restriction in one of two ways:
Code:
Call SubA() : x = a
: SubA : x = a
Back to top
pjc30943



Joined: 02 Dec 2005
Posts: 220

Posted: 13 October 2009, 1:56 AM    Post subject: Reply with quote

Ah...of course. Thanks.
I guess labels are supported for compatibility with assembly.
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 13 October 2009, 2:13 AM    Post subject: Reply with quote

pjc30943 wrote:
I guess labels are supported for compatibility with assembly.
No not really. ZBasic is based on BasicX which in turn is based on VBasic. Just out of interest here is the VBasic documentation for labels and gotos.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 13 October 2009, 2:21 AM    Post subject: Reply with quote

pjc30943 wrote:
I guess labels are supported for compatibility with assembly.
No. Their purpose is to be the target of a GOTO instruction. A GOTO is rarely necessary but occasionally it can be used to good effect when the alternative is even less palatable.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 13 October 2009, 2:41 AM    Post subject: Reply with quote

mikep wrote:
Just out of interest here is the VBasic documentation for labels and gotos.
Although valid, the example is somewhat contrived. The Exit Sub could have been used directly instead of using the goto/label.
Code:

Private Sub ValidateValue(ByVal intValue As Integer)
  If intValue > 10 Then
    Exit Sub
  Else
    ProcessValue(intValue)
    MessageBox.Show("Valid Number Entered")
  EndIf
End Sub

On the other hand, the Exit Sub statement and related Exit statements serve exactly the same purpose as a goto/label combination. It's just that the target is implicit instead of being an explicit label.
Back to top
pjc30943



Joined: 02 Dec 2005
Posts: 220

Posted: 13 October 2009, 18:16 PM    Post subject: Reply with quote

Woops...I didn't realize ZBasic supported goto, but I should have since it's vb based (and looking at it now, there it is in the docs). Hence the assumption that labels was for use with asm GOTOs. Thanks for the clarifications.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group