I should probably know this by now, but been wrestling with it for a while on and off without a clear answer so would appreciate any suggestions.
Suppose I have a form with many controls, but at the beginning a lot of them are hidden and only become visible if the user interactive choices go that way.
With this application I need to take the user input, do a bit of crunching and get a result. The result gives me an integer where the integer is the number of (lets say) a Picturebox control that I now want to make visible. My problem is that I can't seem to find an easy way to reference that Picturebox control using the name of the variable that contains my integer.
Eg:-
Suppose I have three Picturebox controls. Each of them is .Visible = 0
Now I do:-
$i = get-random (1,2,3) # $i is the number of the Picturebox I want to make .Visible = 1
$picturebox$i.Visible = 1
($picturebox)$i.Visible = 1
$($picturebox$i).Visible = 1
$picturebox$($i).Visible = 1
Even $a = $picturebox & "$i"
All crash out.
See what I mean?
Would appreciate any suggestions.
Regards,
Stuart
Using variable in a control reference variable
Using variable in a control reference variable
Should mention that this _can_ be done with New-Variable but its a bit onerous in a large script. Is there any other way?
Using variable in a control reference variable
There are various ways you can do this. One way of doing this is to create an array that references the picture boxes in the Load event:
$script:pictureBoxes = $pictureBox1, $pictureBox2, etc.
Then reference the array to make them visible.
$script:pictureBoxes[$i].Visible = $true
David
$script:pictureBoxes = $pictureBox1, $pictureBox2, etc.
Then reference the array to make them visible.
$script:pictureBoxes[$i].Visible = $true
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.