2014-02-06 5 views
0

나는 이것을위한 올바른 코드를 가지고 있습니다. 내가 예를 누르면 명령이 실행되지만 아니오를 누르면 하위 명령은 명령을 실행하지 않습니다. 누군가가 나를 도울 수 있습니까 ?? (영어 죄송합니다) 비주얼 베이직 프로그래밍에 newbee .. heres는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 코드에서 사용하는 것이 좋습니다 것이 나는 컴파일 타임에 문제로 이것을 보여줄 것입니다.

관련 문제