0

我的问题是有 4 个表格,其中 3 个表格允许我在它们之间传递变量。但是,预订表格的一个表格不允许我将 txtTotal 变量传递给确认表格。

所有其他表格都是我来做的,我没有做任何我能看到的不同的事情......我想也许表格的另一部分禁止我将 txtTotal 传递给 Confirmatin 表格。

以下是 Confirmation 表单,它应该显示 Booking 表单中 lblprice 中的 txtTotal 但什么也不显示

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

如果有帮助,这是预订表格中的所有代码

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

提前致谢!

4

2 回答 2

3

尝试这个

Public frm as new frmBooking
frm.txtTotal.Text=

它应该工作

于 2012-12-01T04:04:07.800 回答
1

您需要使用您创建的 Form 的实际实例,而不是 Class 名称。您还应该确保打开Option Strict

尝试frmBooking.txtTotal.Text代替Booking.txtTotal.Text

于 2012-05-01T22:43:04.370 回答