VB编程 输入一个数x,若x不是整数,则要求继续输入,若是,则输出它是奇数还是偶数

来源:百度知道 编辑:UC知道 时间:2024/05/02 13:49:48
格式尽量写好点

Option Explicit

Private Sub Command1_Click()
Dim m As Single, n As String
m = Val(Text1.Text)
If Fix(m) <> m Then
n = MsgBox("请输入整数", 32, "提示")
Text1.Text = ""
Text1.SetFocus
Else
If m Mod 2 = 0 Then Label1.Caption = "此数为偶数"
If m Mod 2 <> 0 Then Label1.Caption = "此数为奇数"
End If
End Sub

代码如上,期待被采纳!

Private Sub Command1_Click()
Dim a As Double
a = InputBox("请输入一个整数")
there:
If a = Int(a) Then
Cls
If a / 2 = Int(a / 2) Then
Print "偶数"
Else
Print "奇数"
End If
Else
a = InputBox("请输入一个整数")
GoTo there
End If
End Sub