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

Copying data from one array to another

Status
Not open for further replies.

huBBLe

Programmer
May 15, 2001
50
SG
I have the following code:

'************************************************************
Dim KeyValue() As String ' contains "Key=Value" pairs
Dim Value(20) As String ' assuming a max of 21 values

For I% = LBound(KeyValue) to UBound(KeyValue)
Value(I) = GetValue(KeyValue(I))
' GetValue will return the "Value" from "Key=Value"
Next I%
'************************************************************

The array KeyValue will have some pairs like "Key= " which has no value in it.

My question is: Is this method of assigning array values from one to the other correct?
If so, then why is it that whatever statements I have after this for loop does not get executed?

Note that some elements in Value() is a NullString, is this a likely cause of the problem?
 
Dim KeyValue() As String ' contains "Key=Value" pairs
You have a Dynamic Array that has never been allocated with ReDim. The () just defines it as an array but with no dimensions.
If you do a
Debug.Print UBound(KeyValue)
I think you will see a -1, meaning not allocated.
 
I actually assigned values to KeyValue like this:

KeyValue = Split(aString, Chr$(0))

I've tried printing out the elements and they are what I expected them to be. Even the Value array elements I've tried printing them out as I assign from KeyValue to Value, and they worked! So why is it that a simple statement such as a MsgBox AFTER the for Loop never get executed?
 
Thanks John!

I've managed to solve the problem. Found out that I can actually make use of the data directly from the KeyValue array without having to make the copying.

Thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top