2012-05-01 58 views
0

我的问题是有4种形式,其中3种形式允许我在它们之间传递变量..但是一种形式的预订形式不会允许我将txtTotal变量传递给确认形式。Windows窗体不会将变量传递给另一个?

所有其他形式都让我这样做,我没有做任何不同的事情,我可以看到...即时通讯认为,也许形式的另一部分是禁止我将该txtTotal传递给Confirmatin形式。

以下是确认表,它应该在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 

提前致谢!

+0

你是什么txtTotal控制的可见性是私人或公共 –

+0

它的公共.... – MightyMouse

+0

你类名是预订创建它时,表单的名称是什么?通过您创建付款表单的代码来判断,它是frmBooking吗? –

回答

1

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

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

+0

仍然不能得到它出现 – MightyMouse

+0

在'lblprice.Text = frmBooking.txtTotal.Text'上放置一个断点,并逐步通过您的代码,看看发生了什么。也是这个VB.net或Vb6 –

+0

即时通讯使用vb.net – MightyMouse

3

试试这个

Public frm as new frmBooking 
frm.txtTotal.Text= 

它应该工作

相关问题