VBScript Quit versus Exit

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

VBScript Quit versus Exit

Post by BlackWisdom » Sun Nov 27, 2005 6:22 pm

Hey Guys look at this code



if (Drive.IsReady)= false then
filesys.GetFile("MergeSessionIncomplete.exe").Delete True
filesys.copyfile "DynamicMergeDriveNotReady", "DynamicMergeDriveNotReady.txt", True
Exit
else
Set filetxt = filesys.CreateTextFile("CDDriveReady.log", True)
End If

When I run the exe file it generates an Invalid Exit because the code is inside the VBStart and VBEnd tags - but when I create an object using set WShell = CreateObject("Scripting.FileSystemObject") it ignores it because MSched does not use wscript.quit. Any ideas???

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Nov 27, 2005 7:02 pm

You really want to put the code into a VBScript function. Then you can call it from outside the VBSTART/VBEND block and act accordingly. I might not have followed what your code is meant to do entirely but the general idea would be something like this:

VBSTART

Function IsReady

'whatever

if (Drive.IsReady)= false then
filesys.GetFile("MergeSessionIncomplete.exe").Delete True
filesys.copyfile "DynamicMergeDriveNotReady", "DynamicMergeDriveNotReady.txt", True
IsReady = false
else
Set filetxt = filesys.CreateTextFile("CDDriveReady.log", True)
IsReady = true
End if

End Function

VBEND

VBEvaL>IsReady,done
If>done=TRUE

//do other stuff
//call other functions here

Endif
//terminate
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

Post by BlackWisdom » Sun Nov 27, 2005 7:32 pm

Hi Marcus thanks for the quick reply - I guess I didnt explain it very well, this is part of a much larger VBScript I cant run it as a seperate function

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Nov 27, 2005 7:36 pm

Surely instead of Exit you just need more organised logic .... ;-)

Can't you if/then/else/endif around what should/shouldn't happen according to certain conditions?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

Post by BlackWisdom » Sun Nov 27, 2005 8:09 pm

mtettmar you are correct but I guess Im still stuck with my previous dilema:

As I understand it VBScript does not use any goto or Label options. I atempted to use MSched label options inside the script but VBScript throws and error. What Im bassically trying to do is terminate the script if the Drive tray is open. If I dont, the logic below it creates a folder, this is what Im trying to avoid.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Nov 27, 2005 10:29 pm

Ok, well I must be missing something here because surely you'd just use the following construction:

If drivetray NOT open
.. create the folder
.. and do whatever you need to do
Else
.. clean up code if required
EndIf

Split the code up into manageable subroutines and functions if it helps but I really can't see why you can't just use a simple bit of boolean logic to do everything if the drivetray is not open but do nothing if it is.

E.g. why not put all the code you already have into a subroutine called Main:

Sub Main
.. all the code that you want to do if the drive tray is not open
End Sub

Maybe also have one that has the code you want to do if the drive tray IS open:

Sub TrayOpen
.. stuff here
End Sub

Leave any objects and variables that they both need to use declared above them as globals.

And then just do the following:

If drive tray is open
TrayOpen
Else
Main
Endif

And as suggested in my last post, if you are using MacroScript code too then why not either put the VBScript code in a function that returns true if the tray was closed and the operation completed, false if not. That way you can determine after running the VBScript code whether you should exit the script or not. Or just make a VBScript function that returns whether or not the tray is open. E.g.

VBSTART

Function IsTrayOpen
.. Result = true or false depending
End Function

Sub DoStuff
... do what you need if the tray is closed
End Sub

VBEND
VBEval>IsTrayOpen,res
If>res=TRUE
VBRun>DoStuf
.. any other code here
.. bla bla
Endif
//END OF SCRIPT

If you are no further forward it may help if we can see your actual code.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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