Runtime error from same-line commands?

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Runtime error from same-line commands?

Post by pjc30943 »

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

Code: Select all

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: Select all

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: Select all

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.
Paul
GTBecker
Posts: 616
Joined: 17 January 2006, 19:59 PM
Location: Cape Coral

Post by GTBecker »

SubA: is interpreted as a label?
Tom
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

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: Select all

Call SubA() : x = a
: SubA : x = a
- Don Kinzer
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Post by pjc30943 »

Ah...of course. Thanks.
I guess labels are supported for compatibility with assembly.
Paul
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

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.
Mike Perks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

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.
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

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: Select all

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.
- Don Kinzer
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Post by pjc30943 »

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.
Paul
Post Reply