Changing a variable value into a variable name (1 Viewer)

Treason

#@$%#!
Local time
Today, 17:28
Joined
Mar 12, 2002
Messages
340
Assuming this:

Code:
Dim bln1Up, bln2Up, bln3Up as Boolean

Lets say I want to change one of those boolean values based on the middle character... for example

Code:
Private Sub Whatever()
Dim AddKey as Integer
        If ("bg" & AddKey & "Up") = True Then
            Call Correct
            ("bg" & AddKey & "Up") = False
        Else
            Call inCorrect
        End If
End Sub

I want to set bln1Up = True if AddKey = 1...
or set bln2Up = True if AddKey = 2 etc..

Basically I am trying to change a variable value into a variable name...

If Addkey = 1
I want ("bg" & AddKey & "Up") = True to mean bg1up = True


What am I doing wrong?
 

modest

Registered User.
Local time
Today, 17:28
Joined
Jan 4, 2005
Messages
1,220
Not sure that you can do that. It's comparing a string to a value. There is a way to delete and insert lines of codes in a module, but that would be too extreme for what you need. Also, you should probably distinguish what data types the first two variables are (to spead up processing time) right now they're just variants and the last one is the boolean.


**Edit:
Use the array suggestion below. It will be easier and would probably suit your needs better.
 
Last edited:

tkpstock

Cubicle Warrior
Local time
Today, 17:28
Joined
Feb 25, 2005
Messages
206
Why not just use an array?

Code:
Dim blnUp(3) as Boolean
Dim AddKey as Integer
If blnUp(AddKey) = True Then ... Else ... End If

Also, you do know that the following code only makes the third variable (bln3up) a boolean variable? The others would be variants.

Code:
Dim bln1Up, bln2Up, bln3Up as Boolean

To properly declare them, try

Code:
Dim bln1up as Boolean, bln2up as Boolean, bln3up as Boolean
 

Treason

#@$%#!
Local time
Today, 17:28
Joined
Mar 12, 2002
Messages
340
whoa, thanks Tom I didnt catch that declare error

I thought to use arrays, but for some reason I thought Arrays are not available in Access97.

Thanks for the advice guys
 

Users who are viewing this thread

Top Bottom