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. Sending info from Form1 to Form2

Sending info from Form1 to Form2

Scheduled Pinned Locked Moved Visual Basic
question
6 Posts 5 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.
  • P Offline
    P Offline
    Phippsp
    wrote on last edited by
    #1

    frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006

    F H C P 4 Replies Last reply
    0
    • P Phippsp

      frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006

      F Offline
      F Offline
      FeRtoll
      wrote on last edited by
      #2

      Form1 contains: -txtusername -txtpass Form2 contains: -lblUser -lblPass When closeing form1... Dim fr as new Form2 fr.lblUser.text=txtusername.text fr.lblPass.text=txtusername.text fr.showdialog and on Form2 make that labels invisible... Thats all... :-> FeRtoll Software.net -------------------- I fertoll@net.hr I --------------------

      1 Reply Last reply
      0
      • P Phippsp

        frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006

        H Offline
        H Offline
        H is here
        wrote on last edited by
        #3

        The easy way is to create a public variable on Form2 and pass the txtusername.text to that variable Insert on the top of the class of Form2 Public UserName as String In the frmLogin: Dim SecondForm as new form2 SecondForm.UserName=txtusername.text SecondForm.show me.hide You can also use a property but... Hope it helps

        1 Reply Last reply
        0
        • P Phippsp

          frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006

          C Offline
          C Offline
          Chandana Subasinghe
          wrote on last edited by
          #4

          Hi You can do this in many ways. I will suggest 2 ways. 1. Create property on form2... (Say User) and set that property after initialize form2 class. Set the property value to label on it in the form_load Sample code written on VB 2005 Public Class Form2 'Use property for this Public user As String Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Label1.Text = user End Sub End Class Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f2 As Form2 = New Form2() f2.user = Me.txtLogin.Text f2.ShowDialog() End Sub End Class 2. Create constructor in Form2 in order to pass string (Public sub New (user as string)) And pass textbox value then you initialize Form2. Set the passed value to label on it in the form_load No sample code .. (i didnot check this should be work) Try those. Guaranteed to work well Regards, chandana

          1 Reply Last reply
          0
          • P Phippsp

            frmlogin has txtusername.text and txtpassword.text. I would like to take the text that is put into the txtusername.text and send it over to form2 once I hide frmlogin and show form2. I have tried this and failed. Public user as string user = txtusername.text This does not work when I try to put user into form2. So how would I go about this? Thank You -- modified at 18:26 Monday 6th March, 2006

            P Offline
            P Offline
            Phippsp
            wrote on last edited by
            #5

            On form2 I have set Public username as String. On frmlogin this is the code for the ok button when you type in the username and passwoed. If txtpassword.text = frmlogin.tag Then Dim secondforum As New Form2 secondform.username = txtusername.text secondform.show me.hide Else msgbox "Try Again" End If On form2 under Forum Load I have form2.caption = username For some reason the username does not go over to form2. I tried to use F8 to see if the username was being seen in Public username as String but for some reason when in F8 mode it won't skip over to the second form code so I can hover over it with mouse and check. *EDIT* Ok I got it to work not sure what did it though. But aftering changing secondform.username = txtusername.text to secondform.username = me.txtusername.text it worked. And on form2 useing me.caption = username. Thank you for the help! -- modified at 19:05 Monday 6th March, 2006

            M 1 Reply Last reply
            0
            • P Phippsp

              On form2 I have set Public username as String. On frmlogin this is the code for the ok button when you type in the username and passwoed. If txtpassword.text = frmlogin.tag Then Dim secondforum As New Form2 secondform.username = txtusername.text secondform.show me.hide Else msgbox "Try Again" End If On form2 under Forum Load I have form2.caption = username For some reason the username does not go over to form2. I tried to use F8 to see if the username was being seen in Public username as String but for some reason when in F8 mode it won't skip over to the second form code so I can hover over it with mouse and check. *EDIT* Ok I got it to work not sure what did it though. But aftering changing secondform.username = txtusername.text to secondform.username = me.txtusername.text it worked. And on form2 useing me.caption = username. Thank you for the help! -- modified at 19:05 Monday 6th March, 2006

              M Offline
              M Offline
              mayhem_rules
              wrote on last edited by
              #6

              The best way to do this is store the username in a global variable in the login screen. This variable can be accessed throughout the application. With Best Regards, Mayur -- modified at 23:22 Monday 6th March, 2006

              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