Search code examples
vb.netgetdata-transfer

vb.net transfer data from 1 form to another


How do i get data from 1 form to another.

example:

in form 1 when user enters something in inputbox("") send the data to form 2/and display it in.

Sub form1()
  InputBox("Enter something " & Num, "Read Names")
  form2.show
end sub

Solution

  • There are many ways you could do this, for example create an instance of form2, and set the property of one of its controls before you show it. If form2 has a label control called Label1:

        Dim userName As String = InputBox("Whats your name?")
    
        Dim infoForm As New Form2
        infoForm.Label1.Text = userName
        infoForm.ShowDialog()
    

    As per your comment, you can add the string to the listbox the same way you set the lable:

        Dim userName As String = InputBox("Whats your name?")
    
        Dim infoForm As New Form2
        infoForm.lstItinerary.Items.Add(usersName)
        infoForm.ShowDialog()