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.
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.
06-04-2015 01:34 AM
Hallo,
gibt es ähnlich wie bei Kanälen - chnlength - eine Möglichkeit die Länge von Arrays abzufragen?
Is there any possibility to get the length of an array like chnlength?
Gruß
06-04-2015 09:32 AM
Traderhans,
You can use the UBound(array) function to get the largest available index of an array.
-Josh
06-04-2015 11:10 AM
Hi Traderhans,
Note that UBound() returns the upper bound (index) of the array. Since VBScript arrays are zero-indexed, the number of elements in the array is actually 1+UBound(arrayname).
Brad Turpin
DIAdem Product Support Engineer
National Instruments
06-05-2015 03:07 AM
Arrays in vbs are a little tricky.
Thats mainly because
dim arr()
does not create an empty array but an unitialized one. So calling Ubound(arr) will raise an error.
It will also fail to loop using "for each".
So I would suggest to never use "()" to define an array but
dim arr : arr = Array() MsgBox "length=" & ubound(arr) + 1 dim arrElem for each arrElem in arr ' here we can do something Next
Array() will create an initialized Array of length 0. UBound will give -1 as return value.
Usng this returing an array from a funtion works quiet well without having to check for exceptions if array is empty.
Option Explicit Function GetElems() GetElems = Array() ' do some stuff end function dim elems : elems = GetElems dim elem for each elem in elems ' here we can do something Next
If you want to dynamically grow an array you can use redim preserve.
Option Explicit dim arr : arr = Array() redim preserve arr(Ubound(arr) + 1) arr(UBound(arr)) = "Appended text" MsgBox "length=" & ubound(arr) + 1 & VBCRLF & arr(0)
06-05-2015 05:19 AM
Danke / thanks!