Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,099 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,865 people online right now. Registration is fast and FREE... Join Now!




help! need to show text from a textbox in a messagebox

 
Reply to this topicStart new topic

help! need to show text from a textbox in a messagebox

dushi
28 May, 2008 - 10:56 AM
Post #1

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 39



Thanked: 1 times
My Contributions

Hello, i want the user to enter his name in the textbox, and then it must display Hello "username".
My problem is, it only shows me the hello and not the username.
please help!

CODE

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        Dim f2 As New Form2
        Dim dr As DialogResult = f2.ShowDialog()
        Dim TextBox1 As TextBox = New TextBox

        If dr = DialogResult.OK Then

            MessageBox.Show("hello" + TextBox1.Text)

        End If



    End Sub
End Class


User is offlineProfile CardPM
+Quote Post

bflosabre91
RE: Help! Need To Show Text From A Textbox In A Messagebox
28 May, 2008 - 11:35 AM
Post #2

D.I.C Head
**

Joined: 22 Feb, 2008
Posts: 245



Thanked: 1 times
My Contributions
try changing the one line to

CODE

MessageBox.Show("hello" & convert.tostring(TextBox1.Text))


the & symbol is used to concatenate strings
User is offlineProfile CardPM
+Quote Post

dushi
RE: Help! Need To Show Text From A Textbox In A Messagebox
28 May, 2008 - 01:31 PM
Post #3

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 39



Thanked: 1 times
My Contributions
QUOTE(bflosabre91 @ 28 May, 2008 - 12:35 PM) *

try changing the one line to

CODE

MessageBox.Show("hello" & convert.tostring(TextBox1.Text))


the & symbol is used to concatenate strings



i try..it still dont work. do i have to import something?
User is offlineProfile CardPM
+Quote Post

dushi
RE: Help! Need To Show Text From A Textbox In A Messagebox
28 May, 2008 - 02:03 PM
Post #4

New D.I.C Head
*

Joined: 23 Feb, 2008
Posts: 39



Thanked: 1 times
My Contributions
i have done it another way, it works
thnx
User is offlineProfile CardPM
+Quote Post

narmer93
RE: Help! Need To Show Text From A Textbox In A Messagebox
5 Jun, 2008 - 04:07 PM
Post #5

D.I.C Regular
***

Joined: 13 Mar, 2008
Posts: 253



Thanked: 2 times
My Contributions
try the following in the code area of a button
CODE
msgbox("hello "+me.textbox1.text)

remember to leave a space after the word hello

This post has been edited by narmer93: 5 Jun, 2008 - 04:16 PM
User is offlineProfile CardPM
+Quote Post

robertelder
RE: Help! Need To Show Text From A Textbox In A Messagebox
7 Jun, 2008 - 11:09 AM
Post #6

New D.I.C Head
*

Joined: 5 Jun, 2008
Posts: 30



Thanked: 3 times
My Contributions
dushi,

I am not sure, but here is what I am understanding based on your code... When a user clicks on "SAVE" in your Menu tool, you want a new form to appear with a textbox and a "OK" button. The user types in their name in the textbox and presses "OK". When "OK" is pressed that new form should close and a message box appears and says "Hello Mary" (assuming Mary is what was typed in the textbox).

If this is correct, the easiest way to do it would be to use an InputBox control. Something like this:
CODE


Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click

        Dim strName As String
        strName = InputBox("Please type your name")
        MsgBox("Hello " & strName)

End Sub





Alternately, if you want to do this the hard way, well, more power to you! Here are a couple things to consider.

When you created the second form, your code was "Dim f2 As New Form2". This will not work unless you already have another form in your project called Form2.

In your form, you did not provide any properties for the textbox...size, location, which form it is supposed to be displayed on.

I'd recommend that you create a new form, a textbox (for user input), a label (to prompt users), and 2 buttons (OK and Cancel). Here's how I would do it:
CODE


Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click

        Dim f2 As New Form
        Dim TextBox1 As New TextBox
        Dim LabelUserName As New Label
        Dim ButtonOK As New Button
        Dim ButtonCancel As New Button

        With f2
            .MinimizeBox = False
            .MaximizeBox = False
            .AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
            .AutoSize = True
        End With
        With LabelUserName
            .Parent = f2
            .Left = 5
            .Top = 5
            .Width = 117
            .Height = 13
            .Text = "Please type your name:"
        End With
        With TextBox1
            .Parent = f2
            .Left = 5
            .Top = 18
            .Width = 156
            .Height = 20
        End With
        With ButtonOK
            .Parent = f2
            .Left = 14
            .Top = 68
            .Width = 75
            .Height = 23
            .Text = "OK"
            .DialogResult = DialogResult.OK
        End With
        With ButtonCancel
            .Parent = f2
            .Left = 95
            .Top = 68
            .Width = 75
            .Height = 23
            .Text = "Cancel"
            .DialogResult = DialogResult.Cancel
        End With

        f2.ShowDialog()

        If f2.DialogResult = Windows.Forms.DialogResult.OK Then
            MessageBox.Show("Hello " & TextBox1.Text)
        End If
        
End Sub




Finally, since the code sample you posted is contained in a Sub called "SaveToolStripMenuItem_Click" I am assuming that rather than really wanting a MessageBox to display the person's name, you are really trying to use a new form to get a directory or path where the user wants to save a file to. If this is the case, I would recommend using "SaveFileDialog". This will allow the user to browse for a location where they want to save the file. You will still have to provide the code to save the file to that location though.
CODE


Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click

        Dim f2 As New SaveFileDialog
        Dim dr As DialogResult = f2.ShowDialog

        If dr = DialogResult.OK Then
            MsgBox(f2.FileName)
        End If

End Sub



I hope this post help you out!

-Rob
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:29AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month