From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

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
(4,529 Views)

Hi,

You can use this in a subscript:

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

Regards

Christian
CLA, CTA, CLED
0 Kudos
Message 2 of 6
(4,513 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
(4,507 Views)
Solution
Accepted by topic author 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
(4,497 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
(4,489 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
(4,469 Views)