haywire_ES
haywire_ES

Reputation: 99

Using a variable to set properties of a control (The variable contains the name of the control) in VB

For example, in visual basic

Dim VariableName As String
VariableName = "button1"
VariableName.Visible = true

Would set button1 to be visible.

Edit: I got it!

Me.Controls(variableName).Visible = True

Upvotes: 1

Views: 4004

Answers (1)

Mason11987
Mason11987

Reputation: 330

Well VariableName is a string, and strings don't have a a property called "visible".

You want to get the actual Button itself. One way you could do that is something like (untested):

dim btn as Button
for each c in Controls
  if c.name = "button1" then
    btn = c
  end if
next
btn.visible = true

Edit: OP found a better solution, although this could work if you were looking for a textbox with a particular "text" property or something along those lines.

Upvotes: 1

Related Questions