我正在尝试使用消息框来阻止用户继续下一个表单,但不确定出了什么问题。消息框弹出,但仍更改为下一个表单。请问有什么帮助吗?
编辑:感谢您的所有帮助,但现在年龄检查不起作用,因此您可以输入您想要的任何年龄并且它不会显示错误。有任何想法吗。我会将所有更改的代码放在最后
Dim errorcount As Integer = 0
Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
strName = txtName.Text
strAddress = rtfAddress.Text
strCity = txtCity.Text
strEmail = txtEmail.Text
strHomePhone = mtxtHomePhone.Text
strMobilePhone = mtxtMobilePhone.Text
If txtName.Text = "" Then
MessageBox.Show("You must enter full name", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
ElseIf IsNumeric(txtName.Text) Then
MessageBox.Show("Please enter a valid name", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
If txtAge.Text = "" Then
MessageBox.Show("You must enter your age", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
'Else
' strAge = Integer.Parse(txtAge.Text)
End If
'Declaring age check
Dim AgeCheck As Boolean = False
If IsNumeric(txtAge.Text) = True Then
AgeCheck = True
strAge = Integer.Parse(txtAge.Text)
ElseIf strAge < 18 Then
MessageBox.Show("You must be over 18 years old", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
ElseIf strAge > 125 Then
MessageBox.Show("Don't be stupid. You're not that old.", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
ElseIf AgeCheck = False Then
MessageBox.Show("You must enter a valid age", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
End If
If Not IsNumeric(txtAge.Text) Then
MessageBox.Show("Please enter a vadid age", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
If IsNumeric(rtfAddress.Text) Or rtfAddress.Text = "" Then
MessageBox.Show("Please enter your address", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
If IsNumeric(txtCity.Text) Or txtCity.Text = "" Then
MessageBox.Show("Please enter your town/city", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
'if no index hasd been selected
If cmbCounty.SelectedItem = "" Then
MessageBox.Show("Please select a county", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
If Not mtxtHomePhone.MaskCompleted Then
MessageBox.Show("Please enter a valid home phone number", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
If Not mtxtMobilePhone.MaskCompleted Then
MessageBox.Show("Please enter a valid mobile phone number", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
If txtEmail.Text = "" Then
MessageBox.Show("You must enter a valid email address", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
ElseIf Not txtEmail.Text.Contains("@") Then
MessageBox.Show("Not a valid email address", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
btnNext.Enabled = False
errorcount += 1
GoTo A
End If
A:
If errorcount >= 5 Then
MessageBox.Show("Too many errors. Shutting down", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
End
End If
Me.Hide()
frmCreditCardInfo.Show()
End Sub
*Dim errorcount As Integer = 0
Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
strName = txtName.Text
strAddress = rtfAddress.Text
strCity = txtCity.Text
strEmail = txtEmail.Text
strHomePhone = mtxtHomePhone.Text
strMobilePhone = mtxtMobilePhone.Text
If txtName.Text = "" Then
MessageBox.Show("You must enter full name", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
ElseIf IsNumeric(txtName.Text) Then
MessageBox.Show("Please enter a valid name", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
If txtAge.Text = "" Then
MessageBox.Show("You must enter your age", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
'Declaring age check
Dim AgeCheck As Boolean = False
If IsNumeric(txtAge.Text) = True Then
AgeCheck = True
'strAge = Integer.Parse(txtAge.Text)
ElseIf strAge < 18 Then
MessageBox.Show("You must be over 18 years old", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
ElseIf strAge > 125 Then
MessageBox.Show("Don't be stupid. You're not that old.", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
ElseIf AgeCheck = False Then
MessageBox.Show("You must enter a valid age", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit Sub
End If
If Not IsNumeric(txtAge.Text) Then
MessageBox.Show("Please enter a vadid age", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
End If
If IsNumeric(rtfAddress.Text) Or rtfAddress.Text = "" Then
MessageBox.Show("Please enter your address", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
If IsNumeric(txtCity.Text) Or txtCity.Text = "" Then
MessageBox.Show("Please enter your town/city", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
'if no index hasd been selected
If cmbCounty.SelectedItem = "" Then
MessageBox.Show("Please select a county", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
If Not mtxtHomePhone.MaskCompleted Then
MessageBox.Show("Please enter a valid home phone number", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
If Not mtxtMobilePhone.MaskCompleted Then
MessageBox.Show("Please enter a valid mobile phone number", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
If txtEmail.Text = "" Then
MessageBox.Show("You must enter a valid email address", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
ElseIf Not txtEmail.Text.Contains("@") Then
MessageBox.Show("Not a valid email address", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
errorcount += 1
Exit Sub
End If
If errorcount >= 5 Then
MessageBox.Show("Too many errors. Shutting down", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
Me.Dispose()
Exit Sub
'End
'Exit Sub
End If
Me.Hide()
frmCreditCardInfo.Show()
End Sub
结束课程*