quitting a script

Posted by: stuartg

quitting a script - 01/18/06 09:46 AM

Hi
How can I quit from a VBscript in PP?
When running the script manually I just call Wscript.quit, but this is not available within scripts running in PP.
Any ideas?
Stuart
Posted by: cosimo

Re: quitting a script - 01/18/06 10:44 AM

Hi,

If I understand correctly, you want to quit the VBS while the PlanetPress Watch service is running.
If that is the case, you cannot quit while the service is running, it will end when the VBS is finished executing.
On the other hand if you are in a loop, you can put some code there that will quit or exit if it is in a loop.

Thanks
Cosimo
Team OL
Posted by: Philippe F.

Re: quitting a script - 01/18/06 11:16 AM

Stuart,

There's an easy way around it. You need to encapsulate your entire script within a Sub(). Then, you add a line at the very top of the script that calls this new Sub. And within the Sub itself, you simply use an Exit Sub command to interrupt processing.

For instance, let's say your original code looks something like this:
Code:
Dim x
for x=1 to 10
   ' do some processing here
   ' ...
   ' if somecondition then
        wscript.quit
     end if
   ' do some further processing here
   ' ...
next
you could change it to read like this:
Code:
Main

Sub Main()
  Dim x
  for x=1 to 10
     ' do some processing here
     ' ...
     ' if somecondition then
          exit sub
       end if
     ' do some further processing here
     ' ...
  next
end sub
Hope that helps.
Posted by: stuartg

Re: quitting a script - 01/19/06 07:11 AM

Thanks Phillipe
That idea works OK so far.

But if the script already has subroutines, this method won't quit from inside the subroutine. I think I will have to set a global flag and keep checking it.

Thanks for your help
Stuart