Variable Inside Variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Grant

    Variable Inside Variable

    How do I, if at all possible, reference a variable with another variable
    in VB.NET?

    For example, if I have a form with a textbox and a button. Type var1 in
    the textbox

    Private Sub Button_Click(By Val sender As System.Object, ByVal e As
    System.EventArg s) Handles Button.Click

    dim var1 as string
    var1 = "Hello World"
    msgbox( /// display the contents of var1 using what was entered in
    the textbox /// )

    End Sub

    Is this possible?

    Thanks!
  • Armin Zingler

    #2
    Re: Variable Inside Variable

    "Grant" <grantroelofs@g mail.comschrieb
    How do I, if at all possible, reference a variable with another
    variable in VB.NET?
    >
    For example, if I have a form with a textbox and a button. Type
    var1 in the textbox
    >
    Private Sub Button_Click(By Val sender As System.Object, ByVal e As
    System.EventArg s) Handles Button.Click
    >
    dim var1 as string
    var1 = "Hello World"
    msgbox( /// display the contents of var1 using what was entered in
    the textbox /// )
    >
    End Sub
    >
    Is this possible?
    Do you know why variable names have been invented? Do you know what
    compiling means?


    Armin

    Comment

    • Martin H.

      #3
      Re: Variable Inside Variable

      Hello Grant,

      I wonder, for what would you need that?
      If it's about your example, then it is unnecessary as you could
      reference the text box directly.

      TextBox1 contains the text "Hello World"

      Private Sub Button_Click(By Val sender As System.Object, ByVal e As
      System.EventArg s) Handles Button.Click

      MsgBox(TextBox1 .Text)

      End Sub


      Normally, I would not expect a user to know what variables are used in a
      program. So, the input of a variable name which a user entered can match
      the variable name in a program only by a very slight chance.

      However, if there is only a limited number of variables used in your
      program, you could list them in a ComboBox/ListBox and return the
      content of that variable depending on the variable the user selected.
      But consider, that variable names (e.g. var1, var2, var3) don't really
      give much info about what the variable contains. Therefore, it might be
      better to add the contents of the variables to the ComboBox/ListBox and
      let the user choose from those.

      Best regards,

      Martin


      On 20.03.2008 11:32, Grant wrote:
      How do I, if at all possible, reference a variable with another variable
      in VB.NET?
      >
      For example, if I have a form with a textbox and a button. Type var1 in
      the textbox
      >
      Private Sub Button_Click(By Val sender As System.Object, ByVal e As
      System.EventArg s) Handles Button.Click
      >
      dim var1 as string
      var1 = "Hello World"
      msgbox( /// display the contents of var1 using what was entered in
      the textbox /// )
      >
      End Sub
      >
      Is this possible?
      >
      Thanks!

      Comment

      Working...