2012-05-01 84 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= 

它應該工作

相關問題