|
|
| Author |
Message |
pjc30943
Joined: 02 Dec 2005
Posts: 220
|
|
Posted: 13 October 2009, 0:02 AM Post subject: Runtime error from same-line commands? |
|
|
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.
This does NOT work, as subA is never called, but 'x' is correctly set to 'a'. But this configuration does work, of course:
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: |
|
|
| 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: |
|
|
| 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: |
|
|
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: |
|
|
| 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: |
|
|
| 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: |
|
|
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: |
|
|
| 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 |
|
 |
|