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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding to an array

Status
Not open for further replies.

TSComp

Programmer
Feb 18, 2002
7
GB
Hi,

Is it possible to add elements to an array sperately?

I have 50 numbers (1-50).
Numbers are entered by the user before hand. I have counted how many times each number appears, and these are displayed on seperate labels.

A number can appear 0, 1, 2, 3, 4, 5, 6, 7 or 8 times.
I want the program to go through all the numbers, and depending on how many times each appears I want to be added to a different array. I.e. numbers appearing 0 times added to an Array0 , numbers appearing 8 times into an Array8.

Any help would be greatly appreciated,

Thanks,

Tom.
 
hi...

your question is not clear...
can u elaborate it more clearly??

Varnit Good Luck
Varnit
 
Sounds like you are dealing with variable length arrays. Basically, you don't know how many entries will be in the array when you declare it. Declare them as a variable length array (Example: Dim arr8Times() As Integer). After the you use the ReDim statement to change the size of the array (Example: ReDim arr8Times(intArray8Elements) - here you are using a variable intArray8Elements to define, appropriately enough, the number of elements in the array). If you already have data in the array and want to keep it, use the Preserve keyword (Example: ReDim Preserve arr8Times(intArray8Elements) - notice you don't specify the type again on the ReDim statements. That's because it's just used to resize the array).

Kowing this, you should be able to count the occurences of a number, add 1 element to the apropriate array size, then add that number to the appropriate array (use the UBound function to return the last array index, which is the one you just created, for storing the number - you can also use the element counter and just subtract one since the index is zero based). This should allow you to do what you are looking for here.
 
Great, got it working :)

Thanks for the help!

Tom.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top