Can anyone help me with this syntax.. i made 3 forms. and i want form 1 & 2 inputs displayed in form 3.. this is what i made so far.. don't know what to do next

Form 1

Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim ID, sname, course1, year1 As String

    Dim frm3 As New Form3
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        ID = TextBox1.Text
    End Sub
    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        sname = TextBox2.Text
    End Sub
    Private Sub ComboBox1_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.DropDown
        If ComboBox1.MaxDropDownItems > 5 Then
            ComboBox1.Items.Add("BSCoE")
            ComboBox1.Items.Add("BSCS")
            ComboBox1.Items.Add("DIT")
            ComboBox1.Items.Add("DCET")
            ComboBox1.Items.Add("HRS")
            ComboBox1.MaxDropDownItems = 5
        End If
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        course1 = ComboBox1.Text

        If course1 = "BSCoE" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("1st year")
            ComboBox2.Items.Add("2nd year")
            ComboBox2.Items.Add("3rd year")
            ComboBox2.Items.Add("4th year")
            ComboBox2.Items.Add("5th year")
            ComboBox2.MaxDropDownItems = 5
        ElseIf course1 = "BSCS" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("1st year")
            ComboBox2.Items.Add("2nd year")
            ComboBox2.Items.Add("3rd year")
            ComboBox2.Items.Add("4th year")
            ComboBox2.MaxDropDownItems = 4
        ElseIf course1 = "DIT" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("1st year")
            ComboBox2.Items.Add("2nd year")
            ComboBox2.MaxDropDownItems = 2
        ElseIf course1 = "DCET" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("1st year")
            ComboBox2.Items.Add("2nd year")
            ComboBox2.MaxDropDownItems = 2
        ElseIf course1 = "HRS" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("1st year")
            ComboBox2.Items.Add("2nd year")
            ComboBox2.MaxDropDownItems = 2
        End If
        year1 = ComboBox2.Text
    End Sub
    Private _id1 As String

    Public Property [ID1]() As String
        Get
            Return _id1
        End Get
        Set(ByVal Value As String)
            ID = _id1
        End Set
    End Property

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm2 As New Form2

        frm2.ShowDialog()
        Me.Hide()
    End Sub


  
End Class

Form 2

Public Class Form2
    Inherits System.Windows.Forms.Form
    Dim address, bdate, age, contact As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm3 As New Form3
        frm3.ShowDialog()
        Me.Hide()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        TextBox1.Text = address
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        TextBox1.Text = contact
    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        TextBox1.Text = bdate
    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        TextBox1.Text = age
    End Sub
End Class

Form 3

Public Class Form3
    Inherits System.Windows.Forms.Form

    Dim ID2, sname1, course2, year2 As String


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        End
    End Sub



    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Obj As New Form1
        Obj.ID1 = ID2
        ID2 = TextBox1.Text
    End Sub
End Class

Recommended Answers

All 7 Replies

what seems to be the problem anyway?

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        ID = TextBox1.Text

i need to view this in form 3.. in other case.. i want to get the values in the variables in form1 and form2 to finalize it and display at form 3..

2 ways to get this done:
a) load form3, hide it and pass values directly to form 3 objects using a syntax:

Form3.textbox1.value = Me.textbox3.value

. This might require some more changes on the modifier's property of your controls.
b) create variables to hold the data and populate form3 when you load it. These variables can't be declared using Dim, but using Friend or Public. This will make the vars visible to all your forms. Then on Form3 load populate the fields with the appropriate var value.

2 ways to get this done:
a) load form3, hide it and pass values directly to form 3 objects using a syntax:

Form3.textbox1.value = Me.textbox3.value

. This might require some more changes on the modifier's property of your controls.
b) create variables to hold the data and populate form3 when you load it. These variables can't be declared using Dim, but using Friend or Public. This will make the vars visible to all your forms. Then on Form3 load populate the fields with the appropriate var value.

With Form1
            TextBox1.Text = CStr(.ID)
            TextBox2.Text = CStr(.sname)
            TextBox3.Text = CStr(.course1)
            TextBox4.Text = CStr(.year1)
        End With
        With Form2
            TextBox5.Text = CStr(.address)
            TextBox6.Text = CStr(.contact)
            TextBox7.Text = CStr(.age)
            TextBox8.Text = CStr(.d)
        End With

i tried the second option but got stock at Form2 i cant load it in form3 .. but form1 loads..... i also tried the 1st option.. :) but no luck.. i still lack knowledge about that syntax... i cant make it work..

Startup Form:

Friend varID as string = "" 
Friend varSname as string = "" 
Friend varCourse1 as string = "" 
Friend varYear1 as string = "" 
Friend varAddress as string = "" 
Friend varContact as string = "" 
Friend varAge as string = "" 
Friend varD as string = ""

On form1's submit or next or whatever event you find appropriate

varID =id.text 
varSname = sname.text 
varCourse1 = course1.text
varYear1 = year1.text

On form2 submit or next or whatever event you find appropriate

varAddress = address.text
varContact = contact.text
varAge = age.text
varD = d.text

On the 3rd form load event:

Textbox1.text = varID
Textbox2.text = varSname
Textbox3.text = varCourse1
Textbox4.text = varYear1
Textbox5.text = varAddress 
Textbox6.text = varContact
Textbox7.text = varAge
Textbox8.text = varD

PS: If you allow edits in Form3, you can use the same code to reset the values in the textboxes - as long as you don't change the variables.

thanks for the help.. but still your syntax was a bit harsh. got many errors on it :) ... i already found out how to display it with just little editing.. thanks a lot :) .hope i got a brain of yours so it'll be easy next time ..

If you want to show form1 and form2 input values in form3 then drag and drop 2 new label in form3 and follow this syntax

Public Class Form3
    Inherits System.Windows.Forms.Form

    Dim ID2, sname1, course2, year2 As String


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        End
    End Sub



    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Obj As New Form1
        Obj.ID1 = ID2
        ID2 = TextBox1.Text
        'drag a new label from toolbar
         label1.text=form1.textbox1.text
        ' drag one more label
          label2.text=form2.textbox2.text
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.