I have a script that uses VBSTART/VBEND to run some code. In an error condition I would like to have the vbscript stop execution of the macro. However when I try to invoke WScript.Quit I get the error
Microsoft VBScript runtime error: 438
Object doesn't support this property or method: 'WScript.Quit'
What am I doing wrong?
Trying to exit script from a vb subroutine
Moderators: JRL, Dorian (MJT support)
-
- Newbie
- Posts: 5
- Joined: Tue Apr 05, 2016 7:52 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Trying to exit script from a vb subroutine
Yes that Quit object is part of the windows scripting host and has no relevance inside Macro Scheduler. It won't be understood.
What I would do is make your subroutine a function, and if you need to exit, jump to the end of the function, returning a value, say -1 which your main script would check for. Like this:
If you don't want to change your Sub to a Function you could instead set the value of a global VSBcript variable and then use VBEval to see what that is after running the subroutine, and exit or not accordingly.
What I would do is make your subroutine a function, and if you need to exit, jump to the end of the function, returning a value, say -1 which your main script would check for. Like this:
Code: Select all
VBSTART
Function MyFunc
'bla bla
'code here
If exitcondition=true
MyFunc = -1
Else
'continue on
'bla bla
Endif
End Function
VBEND
VBEval>MyFunc,funcResult
if>funcResult=-1
Exit>0
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Newbie
- Posts: 5
- Joined: Tue Apr 05, 2016 7:52 pm
Re: Trying to exit script from a vb subroutine
thanks for the info