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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to return values between two forms

how to return values between two forms

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
3 Posts 2 Posters 1 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.
  • L Offline
    L Offline
    Lisana
    wrote on last edited by
    #1

    I want to return a value from textbox to other form when it opens, how to code the return? my code: In FORM1: file_location = textbox1.text Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click Dim view As New frmView MessageBox.Show(file_location) If view.ShowDialog() = DialogResult.OK Then End If End Sub Public Property ReturnView() As String Get Return file_location End Get Set(ByVal Value As String) file_location = Value End Set End Property In FORM2: Dim AddJob As New frmAddJob view = AddJob.ReturnView TextBox1.Text = view The problem is the view is nothing..it can't pass the value to form2.. does everybody know what's wrong with code? Thanks for your help.. -----------------------Lisa--------------------------

    S 1 Reply Last reply
    0
    • L Lisana

      I want to return a value from textbox to other form when it opens, how to code the return? my code: In FORM1: file_location = textbox1.text Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click Dim view As New frmView MessageBox.Show(file_location) If view.ShowDialog() = DialogResult.OK Then End If End Sub Public Property ReturnView() As String Get Return file_location End Get Set(ByVal Value As String) file_location = Value End Set End Property In FORM2: Dim AddJob As New frmAddJob view = AddJob.ReturnView TextBox1.Text = view The problem is the view is nothing..it can't pass the value to form2.. does everybody know what's wrong with code? Thanks for your help.. -----------------------Lisa--------------------------

      S Offline
      S Offline
      skytribe
      wrote on last edited by
      #2

      If I'm reading this correctly you want to click on a button on form1 which contains a textbox and pass the contents of the textbox to Form2. Simply set up a module with a variable mvarfile_Location as string. When you click on the button. Set this public/friend module level variable and show form2. In the form2 load event - retrieve the contents of this module level variable mvarfile_Location . FORM1 ***** Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Frm2 As New Form2 mvarFileLocation = TextBox1.Text MessageBox.Show(mvarFileLocation ) If view.ShowDialog() = DialogResult.OK Then End If End Sub FORM2 ***** Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load me.text = mvarFileLocation End Sub End Class Module test Public mvarFileLocation As String End Module Of course you could use a class and properties etc. But basically you are putting the contents into a variable/property etc. accessible from both forms. Alternatively You could pass a reference to form2 from form1 and use this to directly access form1.

      L 1 Reply Last reply
      0
      • S skytribe

        If I'm reading this correctly you want to click on a button on form1 which contains a textbox and pass the contents of the textbox to Form2. Simply set up a module with a variable mvarfile_Location as string. When you click on the button. Set this public/friend module level variable and show form2. In the form2 load event - retrieve the contents of this module level variable mvarfile_Location . FORM1 ***** Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Frm2 As New Form2 mvarFileLocation = TextBox1.Text MessageBox.Show(mvarFileLocation ) If view.ShowDialog() = DialogResult.OK Then End If End Sub FORM2 ***** Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load me.text = mvarFileLocation End Sub End Class Module test Public mvarFileLocation As String End Module Of course you could use a class and properties etc. But basically you are putting the contents into a variable/property etc. accessible from both forms. Alternatively You could pass a reference to form2 from form1 and use this to directly access form1.

        L Offline
        L Offline
        Lisana
        wrote on last edited by
        #3

        Thank you very much! It works perfect! Lisa

        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