הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Monday, June 18, 2012 5:00 AM
lets say my form has a button and two text boxes, when the button is pushed i want to dim textbox1.text as new string = textbox2.text. how can i accomplish this because if i put textbox1.text after the dim it dims it as exactly that not whatever is currently in the textbox.
All replies (4)
Monday, June 18, 2012 5:15 AM ✅Answered
DIM is a keyword that is used to create, and optionally initialise, a variable. The textbox already exists, so that syntax won't work.
What you probably mean is something like
Dim Name As String = TextBox1.Text
Dim Address As String = TextBox2.Text
Then Name and Address can be used to do whatever you want to do with those string values.
Monday, June 18, 2012 5:13 AM
This puts the text from textbox2 into textbox1
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = TextBox2.Text
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
You've taught me everything I know but not everything you know.
Monday, June 18, 2012 5:15 AM
The variable (or I imagine more correctly property) Textbox1.Text is created when you add the control to the form. You don't want to create it again. All you have to do is:
Textbox1.Text = Textbox2.Text
Brian
Monday, June 18, 2012 6:01 AM
Hello kyronfelinus,
lets say my form has a button and two text boxes, when the button is pushed i want to dim textbox1.text as new string = textbox2.text. how can i accomplish this because if i put textbox1.text after the dim it dims it as exactly that not whatever is currently in the textbox.
you can not use the controlloTextBox as a variable, because it is a type (control), follow the example of Acamar which states the type of string variable and associates the value of the variable TextBox1.
Regards.
- Carmelo La Monica
- Visual Basic Tips e Tricks Blog
- WordPress.com Blog
- Blogger