Hello Guest it is April 19, 2024, 09:45:59 AM

Author Topic: GoTo Statment?  (Read 4208 times)

0 Members and 1 Guest are viewing this topic.

GoTo Statment?
« on: June 27, 2011, 08:42:23 AM »
I’m trying to set up a branching statement in a Macropump. I’m testing the following code in the VB Script Editor. I get this error message when executed: “Error on line 7- Label not defined” If I put the Label before the GoTo statement it will branch.

Dim torch As String
torch = isoutputactive(output1)
If torch = "true" Then
MsgBox "   Back to manual control "
   
   GoTo test
   
End If
Print torch
test:
Print "Ended"   

The following from VB-Script-commands.pdf.

"Cypress Enable has complete process control functionality.  The
control structures available are Do loops, While loops, For loops,
Select Case, If Then , and If Then Else.  In addition, Cypress Enable
has one branching statement:  GoTo. The Goto Statement branches to
the label specified in the Goto Statement.
 
Goto label1
  .
  .
  .
 
label1:
 
The program execution jumps to the part of the program that begins
with the label "Label1:". "

Also is using Subs good practice in a Macropump.
I would appreciate a copy on someone’s macropump code that has Lables and Subs in it.
Thanks for any help in advance.
Tony

Offline djc

*
  •  47 47
    • View Profile
Re: GoTo Statment?
« Reply #1 on: June 27, 2011, 04:15:43 PM »
I’m trying to set up a branching statement in a Macropump.

Doesn't answer your question, but you can use an ELSE with the IF to remove the need for GOTO. Similarly, SELECT, CASE could be used.

I can't be bothered to look at the Enable documents just now, but wonder if you need a number in the label name (label1 rather than just label)?

OK, now been bothered. Have a look at p.85, the GOTO statement: "Branches unconditionally and without return to a specified label in a procedure." I read that as meaning it is necessary to have the GOTO and the label between your SUB and END SUB statements.
 
« Last Edit: June 27, 2011, 04:27:32 PM by djc »
Re: GoTo Statment?
« Reply #2 on: June 27, 2011, 10:02:19 PM »
Try this code, do you see what you were missing. The VB-Script-Commands.pdf manual or edit the Mach3 wizard code to see subroutines.

Sub test99()
   Dim torch As String
   torch = isoutputactive(output1)
   If torch = "true" Then
      MsgBox "   Back to manual control "
      GoTo test
   End If
   Print torch
   test:
   Print "Ended"   
End Sub
Re: GoTo Statment?
« Reply #3 on: June 28, 2011, 07:38:20 AM »
Thanks for all of your help. You are right, the GoTo statement has to be in a Sub or procedure. I guess what through me was that on page 9 it reads “The program execution jumps to the part of the program that begins with the label "Label1:". “

From VBEnduser.pdf
“Branches unconditionally and without return to a specified label in a
procedure. “

From VB-Script-Commands.pdf on  page 9
“The program execution jumps to the part of the program that begins
with the label "Label1:". “

From VB-Script-Commands.pdf on  page 84
Branches unconditionally and without return to a specified label in a
procedure.

One says Program, one says procedure.
Tony