TextBox Switch
-
I need to figure out how to write code to swap the contents between 2 textboxes by way of a button. Also, I need to learn how to clear the contents of both TextBoxes by clicking the form. I appreciate your help. Jason
-
I need to figure out how to write code to swap the contents between 2 textboxes by way of a button. Also, I need to learn how to clear the contents of both TextBoxes by clicking the form. I appreciate your help. Jason
string s = TextBox1.Text TextBox1.Text = TextBox2.Text TextBox2.Text = s TextBox1.Text = Textbox2.Text = "" Christian Graus - Microsoft MVP - C++
-
I need to figure out how to write code to swap the contents between 2 textboxes by way of a button. Also, I need to learn how to clear the contents of both TextBoxes by clicking the form. I appreciate your help. Jason
I am pasting your reply here and responding to it. Please respond to the board. It may help someone else to read this.
I am learning VB.Net and doing it all on my own so that I can better
understand it from a financial standpoint.
Bare with me because I am learning and not a pro, not even close to an
amateur!!!! :)I put the code into the Private Sub Form1_Load that you posted on the
board andDim String as Text
But something still isnt right........
Am I missing something? Sorry for being an idiot!!!The code I gave you was meant to provide a template, sorry that I assumed that was obvious. First of all, to add a button, just drag it onto the form in the design view. I believe double clicking it will add a method that is called when it is clicked, otherwise the properties window has a lightning type icon, that shows you possible events, you can type a name into the 'Clicked' event to define one. Now, your two text boxes have names. You can change them in the properties box as well ( right click on the textbox and choose properties, although if the window is visible, just clicking will do ). A TextBox has a Text property, so TextBox1.Text assumes one of your text boxes is called TextBox1. I believe that in VB.NET, Dim s as string is the right code to create a temporary string variable ( not string s ), so if you substitute the names of your textboxes, Dim s as string s = Textbox1.Text Textbox1.Text = Textbox2.Text Textbox2.Text =s should swap the strings. And if you create a button/event handler for the 'clear' operation, Textbox1.Text = Textbox2.Text = "" will clear the text boxes. What's happening here is that all the other values get changed to the last one. You can put it on two lines if you find that clearer: Textbox1.Text = "" Textbox2.Text = "" I hope that helps.... Christian Graus - Microsoft MVP - C++
-
I am pasting your reply here and responding to it. Please respond to the board. It may help someone else to read this.
I am learning VB.Net and doing it all on my own so that I can better
understand it from a financial standpoint.
Bare with me because I am learning and not a pro, not even close to an
amateur!!!! :)I put the code into the Private Sub Form1_Load that you posted on the
board andDim String as Text
But something still isnt right........
Am I missing something? Sorry for being an idiot!!!The code I gave you was meant to provide a template, sorry that I assumed that was obvious. First of all, to add a button, just drag it onto the form in the design view. I believe double clicking it will add a method that is called when it is clicked, otherwise the properties window has a lightning type icon, that shows you possible events, you can type a name into the 'Clicked' event to define one. Now, your two text boxes have names. You can change them in the properties box as well ( right click on the textbox and choose properties, although if the window is visible, just clicking will do ). A TextBox has a Text property, so TextBox1.Text assumes one of your text boxes is called TextBox1. I believe that in VB.NET, Dim s as string is the right code to create a temporary string variable ( not string s ), so if you substitute the names of your textboxes, Dim s as string s = Textbox1.Text Textbox1.Text = Textbox2.Text Textbox2.Text =s should swap the strings. And if you create a button/event handler for the 'clear' operation, Textbox1.Text = Textbox2.Text = "" will clear the text boxes. What's happening here is that all the other values get changed to the last one. You can put it on two lines if you find that clearer: Textbox1.Text = "" Textbox2.Text = "" I hope that helps.... Christian Graus - Microsoft MVP - C++
-
I need to figure out how to write code to swap the contents between 2 textboxes by way of a button. Also, I need to learn how to clear the contents of both TextBoxes by clicking the form. I appreciate your help. Jason
Ok I have got it working....... I was missing a few main points, one being the click event for the Form1. In order to clear both textboxes, you will need to go to the form, Base Class Events, then Click and write code as follows: Textbox1.text = " " Textbox2.text = " " this clears the textboxes by clicking the form itself. Thanks again Christian Graus Jason Baggett