Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable problem: How to "variable" a variable (in reports)

Status
Not open for further replies.

JB83

Programmer
Oct 3, 2002
44
NL
Dear reader(s),

I apologise for the title of this thread, but I couldn't define it different. My problem is that I want to use a variable which has to be "variable".

Code:
Dim tempProdGroup As Variant
   
tempProdGroup = Report_ProdForm.lstProdGroup.ListCount

For prodGroupCtr = 0 To tempProdGroup

tempGrpVal = Report_ProdForm.lstProdGroup.ItemData(prodGroupCtr)
    
    If tempGrpVal = "Unit" Then
       
     ln1ProdGroup(prodGroupCtr).Visible = True
    
    Else
  
     ln2ProdGroup(prodGroupCtr).Visible = True
        
    End If
    
Next
 
End Sub

My problem is in the If - Else - End If part: I would like to use the variable prodGroupCtr to check which line has to become visible. I have defined ln1ProdGroup1 through ln1ProdGroup19 and ln2ProdGroup1 through ln2ProdGroup19.

Can this be done with a a concatenated string like

ln1ProdGroup(prodGrpCtr).Visible = True

(but then in a right way of VBA programming :) ) or has this be done completely different?

Thanks in advance,

Jochen.

--------------------------------------------------------------------------------
It never hurts to help and it never helps to hurt.
 
What kinds of objects are the lnProdGroups? You probably have to cycle through all objects of that kind, and find the one with the correct name. You could put all that in a sub, of course.
Example, for the case where the objects are controls on a userform:

sub SetLN(PGonetwo as integer, PGnr as integer, newval as boolean)
dim ctrl as control
for each ctrl in me.controls
if ctrl.name="ln" & PGonetwo & "ProdGroup" & PGnr then
ctrl.visible=newval
endif
next ctrl
end sub

after which you might use

SetLN(1,5,true) to mean

ln1ProdGroup5.Visible = True

Rob
[flowerface]
 
Hi JB83,

I have myself banged my head on a very similar problem (try to concatenate strings to make up a constant name and get its content) for ages. What you want is something like an evaluate function.

The bad news is I never found any solution and I think that it not feasable in VB (though easy and usual in C++).

The good news is: I may be wrong! In which case I'd love to find out how to do!

The only solutions I could implement where indeed to create arrays or similar and loop through. Not very pretty but there doesn't seem to be an alternative!

nath
 
Guys, thank you for your replies! I already found an answer in this thread: thread181-427408 up the good work!

Jochen. --------------------------------------------------------------------------------
It never hurts to help and it never helps to hurt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top