Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does VBScript have a goto command

Status
Not open for further replies.

GregNVMC

IS-IT--Management
Jul 8, 2003
19
0
0
GB
Hi,

Please can someone help?

I'm trying to alter the flow of one of my scripts so that it skips part of the script and goes onto the next bit of the script. I.e.:
--------------------------------------------------------
Code:
if something = false

goto Connect

else

wscript.echo "connected ..."
wscript.exit

endif

:Connect
wscript.echo "not connected ..."
---------------------------------------------------
I've tried using goto but this doesn't seem to work?

Any ideas how I do this are greatly appreciated ...

Kind Regards,

Greg
 
VBScript is a structured language without GoTo instruction, but the On Error GoTo 0 statement.
Try something like this:
Code:
If Not something Then
  WScript.Echo "not connected ..."
Else
  WScript.Echo "connected ..."
End If
WScript.Quit

Hope This Help
PH.
 
Hey!

Try this:

if something = false

goto Connect

else

wscript.echo "connected ..."
wscript.exit

endif

Connect: 'that's how it would look like in VB; i hope it works with VBScript too
wscript.echo "not connected ..."

Note: I haven't tested that so I'm not sure whether it works or not. Let me know if it does.

Gregor
hydralisk@email.si
 
Hello,

A device to branch out to meet more sophisticated conditions is to use the raise method of the error object.

On Error Resume Next
...
'For mutually exclusive conditions i=1,2,3,...
If condition_i Then err.raise i
...
errornumber=err.number
err.clear
Select Case errornumber
Case 1 continue_1
Case 2 continue_2
...
End Select
...
On Error GoTO 0
...

Sub continue_1
...
End Sub
Sub continue_2
...
End Sub
etc

For simple branching out of yes or no connection, you sure do not need such elaboration.

regards - tsuji

PS isoman, could you try out your script first? as PHV had already raised a statement on the goto before you post something.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top