Trying to exit script from a vb subroutine

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
fazleskhan
Newbie
Posts: 5
Joined: Tue Apr 05, 2016 7:52 pm

Trying to exit script from a vb subroutine

Post by fazleskhan » Thu Oct 06, 2016 10:13 pm

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?

User avatar
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

Post by Marcus Tettmar » Fri Oct 07, 2016 8:25 am

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:

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
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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fazleskhan
Newbie
Posts: 5
Joined: Tue Apr 05, 2016 7:52 pm

Re: Trying to exit script from a vb subroutine

Post by fazleskhan » Fri Oct 07, 2016 3:22 pm

thanks for the info

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts