populating a variable with a variable

crossy5575

Registered User.
Local time
Today, 23:49
Joined
Apr 21, 2015
Messages
46
Hi there,

following on from a previous thread i am trying to have a number of temporary variables simultaneously.

This use would be take a concatenated string and make it a variable within a loop
Dim m1days As Integer
Dim m2days As Integer
Dim m3days As Integer

in this case - xroup = "m" & cc & "days" = m1days m2days m3days and so on as the loop continues

Thus for 12 months of the year i could store 12 variables, apply them, then clear them and add another 12 variables.

Another use would be to take a variable string and then make them into an array to be used later on in a form.

The question is what do you define xroup as to enable it to store it as m1days which itself has an integer attached to it?

PHP:
Private Sub initvariables()

Dim m1days As Integer
Dim m2days As Integer
Dim m3days As Integer
Dim m4days As Integer
Dim m5days As Integer
Dim m6days As Integer
Dim m7days As Integer
Dim m8days As Integer
Dim m9days As Integer
Dim m10days As Integer
Dim m11days As Integer
Dim m12days As Integer

Dim firstmon1 As Long
Dim firstmon2 As Long
Dim firstmon3 As Long
Dim firstmon4 As Long
Dim firstmon5 As Long
Dim firstmon6 As Long
Dim firstmon7 As Long
Dim firstmon8 As Long
Dim firstmon9 As Long
Dim firstmon10 As Long
Dim firstmon11 As Long
Dim firstmon12 As Long

Dim mdate2 As String
Dim cc As Integer
Dim dd As Integer
Dim xroup As Variant
Dim yroup As Variant

intmonth = 5 'Me.cbomonth'
intyear = 2016 'Me.cboyear'

If todayx = 1 Then
    firstdate = CLng(DateSerial(intyear, intmonth, Day(Date)))
    Else
    firstdate = CLng(DateSerial(intyear, intmonth, 1))
End If

        dd = 0
        For cc = 1 To 12
                'get number of days in each of the 3 months that we are looking at'
                If cc = 1 Then
                    xroup = "m" & cc & "days"
                   Set xroup = DateDiff("d", firstdate, DateAdd("m", cc, firstdate))
                dd = dd + Controls(xroup)
                yroup = "firstmon" & cc
                temp = getfirstweekday(firstdate + dd)
                    yroup = firstdate + dd - temp + 1
                End If
        Next cc

End Sub

can anyone help load the variable variable please?
thanks
Simon
 
not quite sure what you are asking - is this what you are looking for?


Code:
 for I=1 to 12
    xroup=me("m" & I & "days")
     ...
     ...
next i
 
Thanks

yes it will need an array, but it will also need a variable array. with variable array names like i need for just simple variable below.

PHP:
for I=1 to 12
    xroup=me("m" & I & "days")
     ...
     ...
next i

will create the declared variable m1days, m2days, m3days etc..

I then need to populate m1days=32134, m2days = 234332432, m3days =2343424 and so on.

I am then later on creating a form which will be populated by an array of 300...
that will come in time, first i just need to try and create a loop that will then be very flexible.
 
will create the declared variable m1days, m2days, m3days etc..
think you need to clarify your terminology.

The code I provided assigns a value in the form controls m?days to xoup
 
This is the bit i meant ...

PHP:
For cc = 1 To 12
                'get number of days in each of the 3 months that we are looking at'
                    xroup = "m" & cc & "days"
                   Set xroup = DateDiff("d", firstdate, DateAdd("m", cc, firstdate))
                dd = dd + xroup 
        Next cc

i dont know if the set xroup is right, however i have deleted the controls(xroup) as that is wrong!
 
Last edited:
Pretty sure you need an array.

xroup = "m" & cc & "days"

In that first pass you want xroup to contain the value in the variable named m0days, correct? You do not want xroup to be equal to the string "m0days".

If that is the case, you need to convert all your mdays variables to an array. That way you will be able to reference a specific variable value using only a number.

xroup=mdays(cc)

Try that link I posted the first time.
 
Will give it a go Plog thanks - it will work for this bit, however i might be in trouble trying to get an array into an array later!

will let you know how i go!
Simon
 
Just looked at your code closer and now I am super lost:
Code:
1 ~ xroup = "m" & cc & "days" 
2 ~ Set xroup = DateDiff("d", firstdate, DateAdd("m", cc, firstdate)) 
3 ~ dd = dd + Controls(xroup)

Line 1 xroup is set to a string.
Line2 xroup is set to an integer value?
Line 3 adds a control to an integer?

What's that loop trying to do? Is it trying to update a control on the form? Is it doing a calculation and storing it in a variable? What are you trying to accomplish?
 
Just wanted to say I solved it.
I created a 3 tier array where the Array(x1,x2,x3)
x1 gave me the month, x2 gave me the date, and x3 gave me the information.

thanks for your help
 

Users who are viewing this thread

Back
Top Bottom