MightyMouse
MightyMouse

Reputation: 35

Windows Form won't pass a variable to another?

my problem is that is have 4 forms, 3 of these forms allow me to pass variables between them.. however one form the Booking form won't allow me to pass the txtTotal variable to the Confirmation Form.

All the other forms all me to do this, im not doing anything different i can see... im thinking that perhaps another part of the form is prohibiting me from passing that txtTotal to the Confirmatin form.

The following is for the Confirmation form, it should display the txtTotal in lblprice from the Booking form but shows nothing

Public Class Confirmation

    Private Sub btnBack_Click(sender As System.Object, e As System.EventArgs) Handles btnBack.Click
        Dim FrmPayment As New Payment
        FrmPayment.Show()

        Me.Hide()
    End Sub

    Private Sub btnHome_Click(sender As System.Object, e As System.EventArgs) Handles btnHome.Click
        Dim FrmSelection As New Selection
        FrmSelection.Show()

        Me.Hide()
    End Sub

    Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles lblshow.Click, lbltime.Click, lbldate.Click, lblcust.Click, lblprice.Click

    End Sub

    Private Sub Confirmation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'lblprice displays nothing and the rest of the labels display the correct values
        lblprice.Text = Booking.txtTotal.Text

        lblshow.Text = Selection.cboShowSelect.Text
        lbldate.Text = Selection.cboDateSelect.Text
        lbltime.Text = Selection.cboTimeSelect.Text

    End Sub

End Class

Here is all the code in the Booking form if it helps

Public Class Booking

    Private Sub Booking_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'labels 1,4,6 display information from the comboboxes on the Selection Form
        Label1.Text = Selection.cboShowSelect.Text
        Label4.Text = Selection.cboDateSelect.Text
        Label6.Text = Selection.cboTimeSelect.Text


        Dim i As Integer
        For i = 1 To 4
            cboAdult.Items.Add(i)
            cboChild.Items.Add(i)
            cboSenior.Items.Add(i)
            cboStudent.Items.Add(i)
        Next i

    End Sub





    Public Sub ComboBoxes_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboAdult.SelectedIndexChanged, cboChild.SelectedIndexChanged, cboSenior.SelectedIndexChanged, cboStudent.SelectedIndexChanged
        'Assigned an evet handler to all of the comboboxes then calculates the price and puts in total box

        Dim Totalcombo1, Totalcombo2, Totalcombo3, Totalcombo4, Price As Decimal

        Dim valuecombo1 = (cboAdult.SelectedIndex + 1)  'finds position of option selected & adds one to get number of tickets
        Dim valuecombo2 = (cboChild.SelectedIndex + 1)
        Dim valuecombo3 = (cboSenior.SelectedIndex + 1)
        Dim valuecombo4 = (cboStudent.SelectedIndex + 1)


        'if the submit button is selected without there being a value selected from any combobox then error should appear, saying at least 1 ticket should be purchased.
        If (cboChild.SelectedIndex = -1) Then
            Totalcombo2 = 0
        Else
            Price = 6.5
            Totalcombo2 = valuecombo2 * Price
        End If

        'determines the ticketprice of combobox 1


        If (cboAdult.SelectedIndex = -1) Then
            Totalcombo1 = 0
        Else
            Price = 9
            Totalcombo1 = valuecombo1 * Price
        End If
        'determines the ticketprice of combobox 2


        If (cboSenior.SelectedIndex = -1) Then
            Totalcombo3 = 0
        Else
            Price = 6.5
            Totalcombo3 = valuecombo3 * Price
        End If
        'determines the ticketprice of combobox 3


        If (cboStudent.SelectedIndex = -1) Then
            Totalcombo4 = 0
        Else
            Price = 6.5
            Totalcombo4 = valuecombo4 * Price
        End If
        'determines the ticketprice of combobox 4


        If (cboAdult.SelectedIndex = -1 And cboChild.SelectedIndex = -1 And cboSenior.SelectedIndex = -1 And cboStudent.SelectedIndex = -1) Then
            MessageBox.Show("Please make at least one ticket selection before continuing. ")
        End If





        txtTotal.Text = Totalcombo1 + Totalcombo2 + Totalcombo3 + Totalcombo4
        'adds the totals of the ticketprices and then inserts into the Total label


    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboChild.SelectedIndexChanged

    End Sub


    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim FrmSelection As New Selection
        FrmSelection.Show()

        Me.Hide()
    End Sub



    Sub Form_OpenBooking(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If (cboChild.SelectedIndex >= 0 And (cboSenior.SelectedIndex = -1 And cboAdult.SelectedIndex = -1)) Then
            MessageBox.Show("A child must be accompanied by at least one adult", "Invalid Selection")

        ElseIf (txtTotal.Text > 0) Then         'if the total label is greater than zero then this means at least one ticket selection has been made

            Dim Form3 As New Payment     ' if above is true open Booking Form
            Form3.Show()

            Me.Hide()
        End If

    End Sub


    Private Sub Resetbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        cboAdult.SelectedIndex = -1

        cboChild.SelectedIndex = -1

        cboSenior.SelectedIndex = -1

        cboStudent.SelectedIndex = -1

        txtTotal.Text = 0
    End Sub

End Class

Thanks in advance!

Upvotes: 0

Views: 1499

Answers (2)

Dhinesh
Dhinesh

Reputation: 181

Try this

Public frm as new frmBooking
frm.txtTotal.Text=

It should work

Upvotes: 3

Mark Hall
Mark Hall

Reputation: 54532

You need to use the actual instance of the Form that you created, not the Class name. You should also make sure that you turn on Option Strict.

Try frmBooking.txtTotal.Text instead of Booking.txtTotal.Text

Upvotes: 1

Related Questions