DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Quit/Exit/Kill script from included script

Solved!
Go to solution

Hello,

i got a problem. In main script im including secondary script, in which im calling autoquit. The secondary script returns to main script and continue executing the rest of commands in main script.

How can i kill the script in included scripts?

 

Main.vbs

LogfileWrite "start"
Call ScriptStart(CurrentScriptPath & "Secondary.vbs")
LogfileWrite "im still living"

Secondary.vbs

LogfileWrite "im in and dying"
autoquit
LogfileWrite "i will not execute this command"

When i run Main.vbs, i got following result:

start

im in and dying

i am still living

 

0 Kudos
Message 1 of 6
(6,024 Views)

Hi,

You can use this in a subscript:

call Err.Raise(1,"","")

Regards

Christian
CLA, CTA, CLED
0 Kudos
Message 2 of 6
(6,008 Views)

I tested it and it has the same behavior as autoquit. it kills following instructions in a subscript, but returns to main script and continue.

0 Kudos
Message 3 of 6
(6,002 Views)
Solution
Accepted by Lukas_Doubek

Sorry I misunderstood your question 🙂

I'm not sure if there is anything like this.

The only workaround I know is creating a global variable with globaldim command, set this variable inside the subscript when it's cancelled and check it in the calling script.

 

Main script:

call GlobalDim("Cancelled")
Cancelled = false
call ScriptStart(CurrentScriptPath & "SubScript.vbs")
if not Cancelled then
	'continue here if sub script was not cancelled
	call MsgBox("End")
end if

Sub script:

Cancelled = true
Christian
CLA, CTA, CLED
Message 4 of 6
(5,992 Views)

Yep, this is the solution i was thinking about as well, but i wanted to know if there is some "ultimate autoquit" function 🙂

thanks

0 Kudos
Message 5 of 6
(5,984 Views)

I would use

err.raise

like sugested, because it is the default VBS way to transport errors.

 

Main.vbs

LogfileWrite "start"
on error resume next
Call ScriptStart(CurrentScriptPath & "Secondary.vbs")
if 0 <> err.number then
  LogfileWrite "Error occured in Secondary: " & err.Description
end if
on error goto 0
LogfileWrite "im still living"

Secondary.vbs

LogfileWrite "im in and dying"
call err.Raise(100, currentScriptName, "Secondary failed")
LogfileWrite "i will not execute this command"
0 Kudos
Message 6 of 6
(5,964 Views)