Skip to main content

Kill / Terminate / Quit complete script

Hey,
I want to put a statement into my errorhandler which terminates the complete script.
Is there such an easy statement?
Kind regards
David

Brian Element Tue, 10/18/2016 - 10:55
Sub Main
	If testExitScript() = false Then Exit Sub
	MsgBox "Script complete"
End Sub

Function testExitScript() As Boolean 'returns false if the function failed
	Dim i As Integer
	On Error GoTo exitFunction
	testExitScript = true
	'force an error
	i = 5 / 0
	MsgBox i
	
exitFunction:
	'verify if client error or basic error
	If Client.ErrorCode <> 0 Or Err.Number <> 0 Then 
		testExitScript = false
	End If
End Function

HI David,
If you want to exit the script and IDEA you can use the Client.Quit function as it will close both.
If you want to just exit the script you will need to add a bit of logic.  I have included one way to do it above.  The function will return false if there was an error, you check for it when you call the function and if it is false it will exit the sub main and if it returns true the scipt keeps on running.

Hope this helps.

Brian

Misanthrop Tue, 10/18/2016 - 11:19

Thank you, i will maybe try the Client.Quit, the other thing I use already, but I dont find it really useable
I have another question...
i have an array like the following:
Dim arr
arr = Array("0","5","10")
how can I access second entry of it? arr(1) does not work, it says it doesnt know the function arr then...
any idea?
 

Brian Element Tue, 10/18/2016 - 11:32

In reply to by Misanthrop

Are you trying to set-up a multi dimensional array?  Multi dimensional arrays have to have their size defined when they are created, such as:

Dim myArray(5, 5, 5)

You can only store one piece of information per array address so you would do something like this:

myArray(1, 2, 5) = "This is a test"

msgbox myArray(1, 2, 5)

Is this what you are looking for?

Brian

Misanthrop Tue, 10/18/2016 - 13:48

Hey Brian,
thanks again for your reply. I actually want just a normal 1-dimensional array and i am pretty sure that this code:
Dim arrarr = Array("0","5","10")
creates one.
Now i want to msgbox arr(1) and i would expect, that 5 is shown in a message box, but what actually happens, is the error message described above...
David

Brian Element Tue, 10/18/2016 - 14:01

In reply to by Misanthrop

Hi David,

Yes, if you were using pure Visual Basic that should work but unfortunately IDEAScript is based on an older version of Visual Basic.

So what you need to do is first define your array and then allocate the items.  It seems when you use the Array function your array needs to be defined as a variant, I tried using string for fun and it gave me a type mismatch error.

Dim arrarr() As Variant
 arrarr = Array("0", "5", "10")
 MsgBox arrarr(1)

I found this page that talks about using arrays in VB6 which seem to work in IDEAScript.

http://www.vb6.us/tutorials/understanding-arrays

 

Misanthrop Wed, 10/19/2016 - 01:52

Ah Thank you! Unfortunately you had not the correct solution for me, but it was pretty close...
The problem is: i pass the array as parameter to a function, and inside the function the compiler does not understand, that the array still is an array...
My solution now is, that I recreate the array inside of the function and I copy the input array into it... this seems to work now, but it is really strange!

Brian Element Wed, 10/19/2016 - 07:34
Sub Main
	Dim arrarr() As Variant
 	arrarr = Array("0", "5", "10")
 	Call test(arrarr)	
 End Sub

Function test(myArray() As Variant)
	MsgBox myArray(1)
End Function

 Hi David,

I didn't know you were passing arrays.  The above is the syntax to do that.

Brian