Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Array

Status
Not open for further replies.

Gamecock

Programmer
Aug 7, 2002
13
0
0
US
I am creating a dynamic array in a .bas file
Example : Global event_good()

Trying to load value here
' Array created in browserlib.bas
event_good(count_add) = EventRow.event_number

I get the follwoing error message.

"Illegal Array Reference"

My question, how do you load a value in a dynamic array?
 
Use "Redim Preserve" before loading values in array
 
Your posting doesn't provide all the necessary data to help, but let me see if this helps.

1) Arrays must be dim or reDim to create
Example: dim testdim(4,1) as String

This creates a two dimensional array that can be loaded by individually calling each cell like:

testdim(0,0) = "1st test"
testdim(1,0) = "2st test"
testdim(2,0) = "3rd test"
testdim(3,0) = "4th test"
testdim(4,0) = "5th test"
testdim(0,1) = "6th test"
testdim(1,1) = "7th test"
testdim(2,1) = "8th test"
testdim(3,1) = "9th test"
testdim(4,1) = "10th test"

Or you could setup one or two loops to loop through the inner and outer points and set the values.

Hope this helps!
 
Just to expand on what Gamecock said.


Here is an example

Dim myarray() ' could also be global


Do While "More Data To Put In array"
'Ubound will return the bottom indicy of the array
ReDim Preserve myarray(0 To UBound(myarray) + 1)
myarray(Ubound(myarray)) = "my value"
Loop


Paul


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top