use variable in expression?

  • Thread starter Thread starter richard.iserman
  • Start date Start date
R

richard.iserman

I have a form with a map of the US as a background and an image of a
star on each state. I want to change the visibility property of each
image when a transparent button is clicked that's over each state (I'll
need to do other things as well, but this is a start).
But it seems that I can't use a variable in the expression to change
this property, along the lines of:

'(Where strState is the name of the image)
Me.strState.Visible = True

I tried writing a simple wrapper based on a suggestion I saw elsewhere
in this forum:

Public Function state(strState As String)
state = strState
End Function

And using this instead:

Me.state(strState).Visible = True

It's clear that what I'm doing is wrong on some fundamental level, but
I wonder if there actually is some way to achieve this (short of
writing the expression out 50 times).
 
Kind of surprised by my own stupidity here. After a few more minutes
of fiddling, I figured it out:

total = Me.Controls.Count
total = total - 1
For i = 0 To total
individual = Me.Controls.Item(i).Name
If individual = strState Then
If Me.Controls.Item(i).Visible = False Then
Me.Controls.Item(i).Visible = True
Else
Me.Controls.Item(i).Visible = False
End If
End If
Next
 
Back
Top