Link to home
Start Free TrialLog in
Avatar of SilmaraFlor
SilmaraFlor

asked on

VB6 - Concatenate Variable Names???

Is there a way of concatenating a variable name, "Not the contents". Here is an example of what I want to be able to do:

Dim str1MyVariable1 as String
Dim str1MyVariable2 as String
Dim str2MyVariable1 as String
Dim str2MyVariable2 as String
Dim i as integer

For i = 0 to 4
str(i)MyVariable1 = "Hello"
str(i)MyVariable2 = "Everybody"
Next i
...
Avatar of bobbit31
bobbit31
Flag of United States of America image

why not use an array?

Dim str1(4) as String
Dim str2(4) as String

for i = 0 to UBound(str1)
  str1(i) = "Hello"
next

for i = 0 to UBound(str2)
  str2(i) = "Everybody"
next
Avatar of SilmaraFlor
SilmaraFlor

ASKER

Because some of the variables are arrays already! And I want to use the same function to download my 4 different files which have variable data but same layout!
Does this make sense?

dim myStr as variant
dim str1(1) as Variant
dim str2(1) as string

myStr = str1

str2(0) = "Hello"
str2(1) = "Everybody"
myStr(0) = str2

str2(0) = "Try"
str2(1) = "This"
myStr(1) = str2

myStr(0)(0) will equal "Hello"
myStr(0)(1) will equal "Everybody"
myStr(1)(0) will equal "This"
myStr(1)(1) will equal "This"

SilmaraFlor, basically, the answer is "no"  Once you compile a project, it loses the information about the variables, so concatenation of variable names becomes meaningless.

One way around this, as mentioned above, is to build the variables into multi-dimensional arrays.

Another way is to convert them into collections which are essentially arrays of unrelated items.
ASKER CERTIFIED SOLUTION
Avatar of inthedark
inthedark
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you all for your responses.
inthedark,
Thank you for your examples, they helped me a lot.
I love user defined types becuase they are fast to use.

I think most of the examples would work but there was a syntaxt error here:

FileSpec.DataFromFile=Split(Input(FH,LOF(FH)),VbCRLF)

Should have been:

FileSpec.DataFromFile=Split(Input(LOF(FH), LH),VbCRLF)

Have fund, thanks....