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

Create a dynamic 2-n array where first dimension is an array 1

Status
Not open for further replies.

2781

Technical User
Feb 26, 2002
21
BE
Hi,

I have a one-dimensional array, strInterventionFields(6) filled with 7 field items (option base 0) of one intervention

I now want to transfer this array for each intervention in a second two-dimensional array strInterventions() which should eventually look like strInterventions (52,6) (in case there are 52 interventions).

Thus the code looks as follows:

(option base 0)

x = 0
While ..... (something search for the next intervention)
Dim i as integer
For i = 0 to 6
strInterventions(x,6) = strInterventionFields(i)
Next
x = x+1
Wend

The problem is however that I do not know beforehand how many interventions there will be.

Moreover, to create a dynamic array, only the second dimension can change with Redim Preserve, and the indices cannot be variables but must be constants.

I would greatly appreciate some help in this issue

Thanks,
 
Well, one problem with your code:

x = 0
While ..... (something search for the next intervention)
Dim i as integer
For i = 0 to 6
strInterventions(x,6) = strInterventionFields(i)
Next
x = x+1
Wend

Is that strInterventions(x,6) will always end up as being = to strInterventionFields(6) once the loop is finished going through.

Now strInterventions(x,i) = strInterventionFields(i) would work better.

As for your original question, if strInterventionFields is always going to have 7 elements, you could make a this variable a "Type" instead of an array, and then make a single element array of the type. This way you can use Redim Preserve with no problem.

Robert
 
This sounds like a dictionary object may work well here.

Using two dictionaries, where the first dictionary contains one element for each Intervention. That intervention element is in fact a second dictionary with the seven attribute values associated with the intervention.

You can easily add to the dictionary additional intervensions, and you can also update individual intervention attribute values.



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
many thanks for the two very quick responses.

Indeed, The Vampire, your were correct with the typo error:
strInterventions(x,i) = strInterventionFields(i); instead of (6,i)

Now I do not seem to grasp the crucial second part of your answer. What do you mean by making this variable a "Type" instead of an array?

Neither do I understand your comments Cajun Centurion whereby I should use a dictionary. I am only a beginning amateur, so your additional explanation would be useful.

Many thanks
 
I am not real clear on what you are trying to do but if you know that there will only be 7 interventions for one dimension of the array you could use this code

x = 0
While ..... (something search for the next intervention)
Dim i as integer
ReDim Preserve strInterventions(6,x)
For i = 0 to 6
strInterventions(i,x) = strInterventionFields(i)
Next
x = x+1
Wend

As far as the Vamp's comment on Type you could do something like this

Private Type Interventions
Type0 As String
Type1 As String
Type2 As String
Type3 As String
Type4 As String
Type5 As String
Type6 As String
End Type

Then you can

Dim myInter As Interventions

Then assign values to each element

myInter.Type0 = "Zero"
myInter.Type1 = "One"
myInter.Type2 = "Two"
myInter.Type3 = "Three"
myInter.Type4 = "Four"
myInter.Type5 = "Five"
myInter.Type6 = "Six"

I hope this helps instead of twisting things.


Anything is possible, the problem is I only have one lifetime.
[cheers]
 
2781,

foada pretty much covered the explaination of what a "type" is. Or you could use his other code and take care of it as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top