03-31-2016 02:52 PM
Pounding my head against the desk......oh my I'm going to break my monitor soon.
What am I doing wrong?????
Just for example to find out why things aren't working, I tried this little assign blah to 1, then set the array ChNames array first location to 2, and then reassign blah to ChNames first locaiton which should be 2
As written below, the msgbox reports "1" not the new "2", and as far as I can tell, ChNames doesn't get anything assigned to it. If I try and msgbox str(ChNames(1)) I get no msgbox at all, no error, nothing!
Dim ChNames() Dim ChValues() LContinue = True h = 1 v = 1 blah = 1 ChNames(1) = 2 blah = ChNames(1) Do While (LContinue) Call MsgBoxDisp(str(blah), "MB_OKCancel") ...
03-31-2016 03:02 PM
Update. For fun I made the declarations
Dim ChNames(100) Dim ChValues(100)
And the result is as desired. But shouldn't dynamic declration work too?????
04-01-2016 06:19 AM
Vbs Arrays aren't dynamic allocated.
You need to use
redim
or
redim preserve
to make them grow.
Be aware that they are normally 0 based.
04-01-2016 03:46 PM
Yea, I agree Andreas, but my issue here is sizing the array properly in the beginning. My current solution is to make it so big that it'll always have enough space and redim when I'm done. BUT, even the HELP explains to start with (). Then the example adds a number. But if its dynamic, it shouldn't need a number. Its just confusing here IMOHO.
The MyTable variable is a one-dimensional array with 6 rows and 11 columns. In a two-dimensional array, the first number always specifies the
number of rows and the second number specifies the number of columns. You can also declare arrays and change the array size while the script is running.
These arrays are called dynamic arrays. Declare the array at the beginning with a Dim statement as you do with all other arrays. The difference is that
you do not specify a size or a number of dimensions inside the parentheses. Copy script Dim MyArray()
To use a dynamic array, specify the number and the value of the dimensions with ReDim: Copy script ReDim MyArray(10) ... ReDim Preserve MyArray(15)
These statements use ReDim to specify the size of the dynamic array as 10. The following ReDim statement changes the size of MyArray to 15. The keyword Preserve saves the present content of the array, that means the content of the first eleven elements are maintained. If the keyword is missing, the contents of the array to be resized are completely deleted. You can change the size of a dynamic array any number of times. However, the data of the eliminated elements is lost when the array is reduced. Notice also, that you can modify only the last dimension of the array with the ReDim statement.
05-02-2016 12:28 PM
How about using an ArrayList?
https://msdn.microsoft.com/en-us/library/system.collections.arraylist_members%28v=vs.90%29.aspx
I use anytime I need an array when I don't know what size I need plus it has some cool functions.
GlobalDim "ArraytList" Set ArrayList = CreateObject( "System.Collections.ArrayList" ) ArrayList.Add "First Value" 'Adds a value to the array list ArrayList.Add "Second Value" 'Adds a second value to the array list msgbox(ArrayList.Item(0)) 'Displays first item