2014-02-06 91 views
0

我有正確的代碼。當我按是的命令將執行,但是當我按下否子不退出它仍然執行命令..可以有人幫助我??即時通訊在VB編程一個newbee。(對不起,我英文)如何使用MSGBOX是否

繼承人的代碼

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     Dim payed As Integer 
     Dim balance As Integer 
     Dim paying As Integer 
     Dim d As Integer 
     Dim c As Integer 
     Try 

      Dim ans As Integer 
      If TextBox7.Text = "" Or 0 Then 

       MsgBox("please enter amount", MsgBoxStyle.Critical) 
      Else 
       If TextBox6.Text = 0 Then 

        MsgBox("the student is fully payed", MsgBoxStyle.Critical) 
       Else 
        ans = MsgBox(" are you want to upadate the students payment? ", MsgBoxStyle.YesNo, "confirm ") 
        If MsgBoxResult.Yes Then 


         payed = Val(TextBox5.Text) 
         balance = Val(TextBox6.Text) 
         paying = Val(TextBox7.Text) 
         d = payed + paying 
         c = balance - paying 
         TextBox5.Text = d 
         TextBox6.Text = c 

         Dim SqlQuery = "UPDATE sample SET [Payed Amount] ='" & TextBox5.Text & "',Balance ='" & TextBox6.Text & "' WHERE ID = " & a & " ; " 
         Dim sqlcommand As New OleDbCommand 
         With sqlcommand 
          .CommandText = SqlQuery 
          .Connection = conn 
          .ExecuteNonQuery() 
         End With 
         MsgBox("student payment succesfully updated") 
         My.Computer.Audio.Play(My.Resources.CASHREG, AudioPlayMode.Background) 
         If TextBox6.Text = 0 Then 
          MsgBox("the student is now fully paid", MsgBoxStyle.Information) 
          TextBox7.Text = "" 
         Else 

          MsgBox("students current balance is " & Convert.ToString(TextBox6.Text)) 
          LoadListView() 
          TextBox7.Text = "" 
         End If 
        Else 
         Exit Sub 
        End If 
       End If 
      End If 
     Catch ex As Exception 
      MsgBox(ex.Message) 
     End Try 

回答

2

這是你的代碼的一部分:

ans = MsgBox(" are you want to upadate the students payment? ", MsgBoxStyle.YesNo, "confirm ") 
If MsgBoxResult.Yes Then 

您分配消息的結果請致電ans,但您並不是實際上測試的值爲ans。當你說

If MsgBoxResult.Yes Then 

這將總是正確,因爲MsgBoxResult.Yes是一個恆定值,它總是會站出來爲True。實際上,你想這個測試是

If ans = MsgBoxResult.Yes Then 

我微微一驚,你有什麼樣的編譯,雖然VB.NET是不是我的強項。我建議你總是在你的代碼中使用Option Strict,我相信這會在編譯時顯示這個問題。