View Full Version : Exit VBScript
rjones0604
12-14-2005, 01:10 PM
I'm writing a VBScript step, and need to exit the script prematurely. However, WScript.Quit is not supported. So, how does one exit a script?
Rob
kinook
12-14-2005, 02:02 PM
Use structured programming or put your code in a subroutine and exit the subroutine:
MySub ' call the subroutine
Sub MySub()
' some code
Exit Sub
' some more code
End Sub
rjones0604
12-14-2005, 02:08 PM
So what you're really saying is that there is no way to exit a script, the script 'code' must completely execute. If I want to stop execution, I have to enclose the entire remainder of the script inside an 'If' test...
BTW, putting code in a subroutine and using the sub's 'Exit Sub' call does not shutdown a script, it merely exits the subroutine.
kinook
12-14-2005, 02:15 PM
How would "exiting the script" be different from exiting the subroutine before the end? An Exit Sub statement within a subroutine prevents the remainder of the subroutine code from executing, which has the same effect as calling WScript.Quit in a .vbs file (preventing the remainder of the code in the .vbs file from executing).
rjones0604
12-14-2005, 02:16 PM
Actually, the VBP online help says this about WScript:
A helper object to provide compatibility with WSH script code. It's actually an alias for the Builder object, so all methods on each object are available on both.
So, that means that the .Quit method is supposed to be available, right?
kinook
12-14-2005, 02:30 PM
Actually, only the WScript CreateObject, Sleep, and Echo methods are supported (we'll update the docs to be explicit about that). But, again, there are other ways to exit a script "prematurely." Also, if you want to stop the build with an error from within script code, use
Err.Raise 1, Step.Name, "error description"
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.