5 Replies - 18749 Views - Last Post: 07 June 2008 - 12:09 PM Rate Topic: -----

#4 dushi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 40
  • Joined: 23-February 08

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

Post icon  Posted 28 May 2008 - 11:56 AM

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!

	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



Was This Post Helpful? 1

#5 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

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

Posted 28 May 2008 - 12:35 PM

try changing the one line to

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



the & symbol is used to concatenate strings
Was This Post Helpful? 0
  • +
  • -

#6 dushi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 40
  • Joined: 23-February 08

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

Posted 28 May 2008 - 02:31 PM

View Postbflosabre91, on 28 May, 2008 - 12:35 PM, said:

try changing the one line to

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?
Was This Post Helpful? 0
  • +
  • -

#7 dushi  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 40
  • Joined: 23-February 08

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

Posted 28 May 2008 - 03:03 PM

i have done it another way, it works
thnx
Was This Post Helpful? 0
  • +
  • -

#8 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

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

Posted 05 June 2008 - 05:07 PM

try the following in the code area of a button
msgbox("hello "+me.textbox1.text)

remember to leave a space after the word hello

This post has been edited by narmer93: 05 June 2008 - 05:16 PM

Was This Post Helpful? 0
  • +
  • -

#9 robertelder  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 30
  • Joined: 06-June 08

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

Posted 07 June 2008 - 12:09 PM

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:

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:

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.

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1