Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. TextBox Switch

TextBox Switch

Scheduled Pinned Locked Moved Visual Basic
helptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Baggett
    wrote on last edited by
    #1

    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

    C J 3 Replies Last reply
    0
    • J Jason Baggett

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      string s = TextBox1.Text TextBox1.Text = TextBox2.Text TextBox2.Text = s TextBox1.Text = Textbox2.Text = "" Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • J Jason Baggett

        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

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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 and

        Dim 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++

        A 1 Reply Last reply
        0
        • C Christian Graus

          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 and

          Dim 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++

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Thanks!!! I think I have a good handle on it now from reading this post. I'll try this tonight and let you know how it goes tomorrow. This is great information. Thanks again Christian!!! :-D JB

          1 Reply Last reply
          0
          • J Jason Baggett

            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

            J Offline
            J Offline
            Jason Baggett
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups