12-22-2015 12:31 PM
I'm working with a matrix, and I want to make sure it's actually a matrix. If I use Ubound(MyMatrix,2), I get an error if the second dimension is not declared. I suppose I could catch the error if Ubound creates one, but I cannot find a method in VB to return the number of dimensions of a matrix. Does diadem have any such function?
Solved! Go to Solution.
12-23-2015 09:04 AM
You can use a few lines of vbs to determine the dimension. VBS does not offer the functionallity as far as I know.
Function GetArrayDimension(ByVal arr) GetArrayDimension = null If IsArray(arr) Then Dim i : For i = 1 To 60 On Error Resume Next UBound arr, i If Err.Number <> 0 Then GetArrayDimension = i-1 Exit Function End If Next GetArrayDimension = i End If End Function
12-23-2015 09:07 AM
Thanks. That's what I ended up implementing. Don't you have to use "On Error Goto 0" to turn error handling back on?
12-23-2015 11:51 AM
Hi Russell,
If you don't use "On Error Goto 0" afterwards, the rest of your code will run with error messages suppressed, and you will find it impossible to debug.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
12-29-2015 03:11 AM
Hmm potentially I should have inserted an
on error goto 0
but it is not necessary. What might be wrong is that err.number does not end up with 0 but it does not influence the rest of the script if err.number is not checked.
on error goto 0
does two things. Reset the err.number to 0 and set the local error handler back to raise.
Local means that there is one for each level. If a function/sub does call
on error resume next
this does not affect called functions/sub nor does it effect the calling code.
Run the following example to have look. cr raises an error even if it was switched off by c and the final division by zero in the main code also shows up.
Option Explicit dim txt txt = txt & "e: " & err.number & VBCRLF err.Clear txt = txt & "e: " & err.number & " a:" & a() & " e: " & err.number & VBCRLF err.Clear txt = txt & "e: " & err.number & " b:" & b() & " e: " & err.number & VBCRLF err.Clear txt = txt & "e: " & err.number & " c:" & c() & " e: " & err.number & VBCRLF err.Clear MsgBox Txt dim res : res = 1 / 0 function a() on error resume next dim res : res = 1 / 0 a = err.number on error goto 0 end function function b() on error resume next dim res : res = 1 / 0 b = err.number end function function c() on error resume next c = cr() end function function cr() dim res : res = 1 / 0 cr = 101 end function
12-29-2015 03:14 AM
Be aware that the err.number is also set back during initialize
Option Explicit err.number = 4711 MsgBox err.number on error resume next MsgBox err.number
will show 0 in the second box