none
Visual Basic - How to determine the value of a TEXTBOX

    Question

  • Let say I have a textbox with the NAME property of VAR1 and I would like to display the value entered in the textbox what must I do.  This is the code I have in my CLICK event

    dim var1 as string

    messagebox(var1)

    But I do not get the value I enter in the textbox.   What must I do to get the value to display?


    ecb

    Monday, December 03, 2012 8:02 PM

Answers

  • I think you have inadvertently confused us by saying that the name of the TextBox is Var1 and also showing code that declares var1 to be a String.

    If what you wants to do is display a MessageBox that contains the same text as a TextBox called Var1 then this is the code that you would use (assuming the code appears somewhere in the class for the form that contains the TextBox).

    MessageBox.Show(Me.Var1.Text)

    In this case you do not need to declare Var1 as a String.

    Tuesday, December 04, 2012 1:06 AM
  • Hello All,

    Being new at VB, I guess what I am looking for is the exact code that will display the value of VAR1 after it is type in the textbox. 

    dim this as string

    messagebox.show(this.var1.text)

    I get ERROR:   VAR1 is not a member of string

    What code should I enter?

    Ed.


    ecb

    Let's start at the basics. Let's say that I have a TextBox named "TextBox1" and you want to show what the user has typed in there.

    In an event (you choose what event, like maybe a button click), you'd use:

    MessageBox.Show(TextBox1.Text)

    That will display a dialog showing the text of whatever is in the .Text property of TextBox1.


    Please call me Frank :)

    Tuesday, December 04, 2012 1:07 AM

All replies

  • messagebox(this.VAR1.Text)


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    Monday, December 03, 2012 8:07 PM
  • MsgBox(Me.Controls.Find(var1, True)(0).Text)

    If a post is helpful to you or solves a problem, remember to mark it as answer, propose it as answer or vote up.
    Check out my development so far!

    Monday, December 03, 2012 8:21 PM
  • Hello EdCal,

    Let say I have a textbox with the NAME property of VAR1 and I would like to display the value entered in the textbox what must I do.  This is the code I have in my CLICK event

    dim var1 as string

    messagebox(var1)

    But I do not get the value I enter in the textbox.   What must I do to get the value to display?


    ecb

    another sample of code,

     Dim var1 As String = TextBox1.Text
            MsgBox(var1)

    or

     Dim var1 As String = TextBox1.Text
            MessageBox.Show(var1)

    Regards.

    • Proposed as answer by Davester Monday, December 03, 2012 9:46 PM
    Monday, December 03, 2012 9:18 PM
  • Pieter,  When I use you code messagebox(this.var1.text)  I get two error messages

    Error 1: 'messagebox' is a type and can not be used

    Error 2: 'this' is not declared

    Please submit exact code because I am a beginner.

    Ed.


    ecb

    Monday, December 03, 2012 11:36 PM
  • Pieter,  When I use you code messagebox(this.var1.text)  I get two error messages

    Error 1: 'messagebox' is a type and can not be used

    Error 2: 'this' is not declared

    Please submit exact code because I am a beginner.

    Ed.


    ecb

    You need to use the .Show method to display a message.

    If I read correctly, you've named your TextBox as "Var1" and in your code you're declaring a string variable as "var1"? That's really not a good practice. Consider naming each of them to something more meaningful.


    Please call me Frank :)

    Monday, December 03, 2012 11:45 PM
  • Hello All,

    Being new at VB, I guess what I am looking for is the exact code that will display the value of VAR1 after it is type in the textbox. 

    dim this as string

    messagebox.show(this.var1.text)

    I get ERROR:   VAR1 is not a member of string

    What code should I enter?

    Ed.


    ecb

    Tuesday, December 04, 2012 12:55 AM
  • I think you have inadvertently confused us by saying that the name of the TextBox is Var1 and also showing code that declares var1 to be a String.

    If what you wants to do is display a MessageBox that contains the same text as a TextBox called Var1 then this is the code that you would use (assuming the code appears somewhere in the class for the form that contains the TextBox).

    MessageBox.Show(Me.Var1.Text)

    In this case you do not need to declare Var1 as a String.

    Tuesday, December 04, 2012 1:06 AM
  • Hello All,

    Being new at VB, I guess what I am looking for is the exact code that will display the value of VAR1 after it is type in the textbox. 

    dim this as string

    messagebox.show(this.var1.text)

    I get ERROR:   VAR1 is not a member of string

    What code should I enter?

    Ed.


    ecb

    Let's start at the basics. Let's say that I have a TextBox named "TextBox1" and you want to show what the user has typed in there.

    In an event (you choose what event, like maybe a button click), you'd use:

    MessageBox.Show(TextBox1.Text)

    That will display a dialog showing the text of whatever is in the .Text property of TextBox1.


    Please call me Frank :)

    Tuesday, December 04, 2012 1:07 AM
  • Thanks to everyone.  It is working now.   I have purchase a book over the web when I get it I will spend many hours learning VB so I do not have to ask such basic questions,  But I will need help of the things I do not understand.

    Ed.


    ecb

    Tuesday, December 04, 2012 2:21 AM
  • Thanks to everyone.  It is working now.   I have purchase a book over the web when I get it I will spend many hours learning VB so I do not have to ask such basic questions,  But I will need help of the things I do not understand.

    Ed.


    ecb

    Ed,

    For whatever little I helped, you're certainly welcome! :)

    *****

    There's nothing wrong with asking questions here no matter the level, but I agree that buying a "Getting Started" book is a good idea. Do be sure that it's a reliable source as there is an abundance of totally WRONG stuff that I've seen (for example, on YouTube).

    I've seen some here say that this is a good place for learning. I agree and disagree. ;-)

    In terms of enhancing your knowledge, it definitely is, but learning from scratch I would have to vote no. It's easy to get opinions confused with "commonly accepted methods" and that leaves you nothing but frustrated.

    Been there done that, got the tee-shirt!

    You'll do fine though - but don't let your frustration get the best of you. I'll make a bet with you in public right now (for any reasonable amount):

    Keep at it for a year. One year from today, you'll be BLOWN AWAY with how much more you know, can do, and understand about it IF you keep at it. You'll get angry, frustrated, flustered, want to uninstall it ... don't succumb to that.

    KEEP GOING ANYWAY.

    Bet money on it. :-)


    Please call me Frank :)

    • Proposed as answer by Xiong Wei, Jin Tuesday, December 04, 2012 6:06 PM
    Tuesday, December 04, 2012 2:38 AM
  • Hello EdCal,

    Thanks to everyone.  It is working now.   I have purchase a book over the web when I get it I will spend many hours learning VB so I do not have to ask such basic questions,  But I will need help of the things I do not understand.

    Ed.


    ecb

    just a clarification on me if there is only the variable var1 and none there are others at the method or event that they can go in conflict with the class-level variable and can also omit it, it is not necessary unless you decide to call the TextBox control var1 even if they strongly discourage, checks must have a name as far as possible aligned to their function within the application itself.

    Regards.


    Tuesday, December 04, 2012 6:42 AM