Concatenation Syntax Question

April15Hater

Accountant
Local time
Today, 17:23
Joined
Sep 12, 2008
Messages
349
Hi,
I am trying to combine a string and integer to define a variable. I think it is best shown by example. This is what I thought would work:
Code:
For IntX = 1 to 4
     intWeek & IntX = FindLastBillableWeeks(4, IntX)
Next IntX
The ending result would replace this code:
Code:
intWeek1 = FindLastBillableWeeks(4, 1)
intWeek2 = FindLastBillableWeeks(4, 2)
intWeek3 = FindLastBillableWeeks(4, 3)
intWeek4 = FindLastBillableWeeks(4, 4)
This is obviously the abridged version of the issue as intWeek can be much higher than 4. WHat i'm really trying to do is make a dynamic variable.

Thanks Guys!

Joe
 
Hi,
I am trying to combine a string and integer to define a variable. I think it is best shown by example. This is what I thought would work:
Code:
For IntX = 1 to 4
     intWeek & IntX = FindLastBillableWeeks(4, IntX)
Next IntX
The ending result would replace this code:
Code:
intWeek1 = FindLastBillableWeeks(4, 1)
intWeek2 = FindLastBillableWeeks(4, 2)
intWeek3 = FindLastBillableWeeks(4, 3)
intWeek4 = FindLastBillableWeeks(4, 4)
This is obviously the abridged version of the issue as intWeek can be much higher than 4. WHat i'm really trying to do is make a dynamic variable.

Thanks Guys!

Joe

Like the man once said when asked to provide impossible directions:

"You can't get there from here"

You cannot create a new variable name by adding two variables together. Having said all that, I think that this approach might work:
Code:
Dim IntWeek(4) As Integer
 
For IntX = 1 to 4
     intWeek(IntX) = FindLastBillableWeeks(4, IntX)
Next IntX

This approach assumes that the result of FindLastBillableWeeks() is an Integer. If it is not, you will need to make the appropriate adjustments for whatever type it is.
 
I believe this should do it:
Code:
For IntX = 1 to 4
     Me.Controls("intWeek" & IntX) = FindLastBillableWeeks(4, IntX)
Next IntX
 
I believe this should do it:
Code:
For IntX = 1 to 4
     Me.Controls("intWeek" & IntX) = FindLastBillableWeeks(4, IntX)
Next IntX

Very interesting. I didn't know that you could do that with Control Names. Once again I learn something new.

I responded assuming he was looking to create a dynamic VB variable, and since I was not aware that was possible, I suggested an array as a substitute.
 
Last edited:
Very interesting. I didn't know that you could do that with Control Names. Once again I learn something new.

I responded assuming he was looking to create a dynamic VB variable, and since I was not aware that was possible, I suggested an array as a substitute.

Be aware that the x in object(x) is dynamic meaning the object in object(x) in one situation could be object(y) in another situation...;)
 
Hey Guys, Happy Monday! I was looking for a dynamic variable, but I never would have guessed to turn to controls to make it work. Thanks for the input guys!
 

Users who are viewing this thread

Back
Top Bottom