VB的if语句判断后跳过部分内容

2025-03-24 06:13:22
推荐回答(2个)
回答1:

Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
    MsgBox "输入非数值数据,请重新输入", , "数据检验"
    Text1.Text = ""
    Text1.SetFocus
Else
    Dim t%, a%, b%, c%
    t = Val(Text1.Text)
    If t > 999 Or t < 100 Then
        MsgBox "请正确输入三位数", , "数据检验"
        Text1.Text = ""
        Text1.SetFocus
    Else
        a = t Mod 10
        b = (t Mod 100) \ 10
        c = t \ 100
        Text2.Text = a * 100 + b * 10 + c
    End If
End If
End Sub

回答2:

用Exit Sub退出Sub过程

Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "输入非数值数据,请重新输入", , "数据检验"
Text1.Text = ""
Text1.SetFocus
Exit Sub '退出此过程
End If
Dim t%, a%, b%, c%
t = Val(Text1.Text)
If t > 999 Or t < 100 Then
MsgBox "请正确输入三位数", , "数据检验"
Text1.Text = ""
Text1.SetFocus
Exit Sub '退出此过程
End If

a = t Mod 10
b = (t Mod 100) \ 10
c = t \ 100
Text2.Text = a * 100 + b * 10 + c
End Sub