Machsupport Forum
		Mach Discussion => VB and the development of wizards => Topic started by: Tony Bullard 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
 
 
- 
				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.
 
- 
				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
- 
				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