HELP! How to Reference a Variable then add value to it

L

Lisab

I have several global variables that are of type INTEGER with simular names
and would like to reference them in code. for example my global variables
are named as follows: intPHOpen, intPHDAOpen, intPHTROpen

my code loopes through records; I want the record Type and Category (PH,
TR, DA) to determine which variable should have a value added to it.

I have a local variable called strVarName that is of Type STRING and my
code sets this string to the name of the globla variable that I want to
reference

I am having trouble in the SELECT CASE section of my code. There is where I
want to add value to the global variable (strVarName) . currently my code
looks like this
--------------------------------------
Do Until SourceRS.EOF
If SourceRS!Type = "M" Then
'add value to Multifamily open count
intMFOpen = intMFOpen + SourceRS!countvalue
strVarName = "intMF"
ElseIf SourceRS!Type = "P" Then
'add value to PublicHousing opencount
intPHOpen = intPHOpen + SourceRS!countvalue
strVarName = "intPH"
End If

Select Case SourceRS!Category
Case "DA"
strVarName = strVarName & "DAOpen"
strVarName.Value = strVarName.Value + SourceRS!countvalue
Case "TC"
Case "TR"
End Select
....
----------------------------

I am having problems in the section of code that says:
strVarName.value = strVarName.Value + SourceRS!CountValue
I know it is something simple I should do instead

note: at this point in the code strVarName = intPHDAOpen or intMFDAOpen
this is the name of my global variable that I want to add value to.

I also tried the following in my SELECT CASE statement. I declared
strVarName as VARIANT and glblVariable as VARIABLE
 
D

Douglas J. Steele

Sorry, I don't believe there's any way to do that.

What you could do is use a two-dimensional array, rather than individual
variables. With the correct constants defined, you could refer to
intOpen(cPH, cDA) rather than intPHDAOpen.
 
L

Lisab

Thank you.

I decided to do it another way. Just thought I could save myself some
keystrokes if I could accomplish coding a string to determine the variable
name to use.

This is what my code now looks like and it works:
----------------------------
Do Until SourceRS.EOF
If SourceRS!Type = "M" Then
'add value to Multifamily open count
intMFOpen = intMFOpen + SourceRS!countvalue
strVarName = "MF"
ElseIf SourceRS!Type = "P" Then
'add value to PublicHousing opencount
intPHOpen = intPHOpen + SourceRS!countvalue
strVarName = "PH"
End If

Select Case SourceRS!Category
Case "DA"
If strVarName = "MF" Then
intMFDAOpen = intMFDAOpen + SourceRS!countvalue
ElseIf strVarName = "PH" Then
intPHDAOpen = intPHDAOpen + SourceRS!countvalue
End If
Case "TC"
If strVarName = "MF" Then
intMFTCOpen = intMFTCOpen + SourceRS!countvalue
ElseIf strVarName = "PH" Then
intPHTCOpen = intPHTCOpen + SourceRS!countvalue
End If
Case "TR"
If strVarName = "MF" Then
intMFTROpen = intMFTROpen + SourceRS!countvalue
ElseIf strVarName = "PH" Then
intPHTROpen = intPHTROpen + SourceRS!countvalue
End If
End Select
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top