我有正确的代码。当我按下是的命令将执行但当我按下否则不退出它仍然执行命令..有人可以帮助我?我是vb编程的新手......(对不起英文)
继承人的代码
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
答案 0 :(得分: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
Option Strict
,我认为这会在编译时将其显示为一个问题。