好的程序来了,自己特意为你写的,已经验证OK!!!
Private Sub Command1_Click()
Dim num As Single
num = Val(Text1.Text)
If num > 50 Then
Label2.Caption = "小"
Else
Label2.Caption = "大"
End If
End Sub
Private Sub Form_Load()
Label1.FontSize = 12
Label1.AutoSize = True
Label1.Caption = "请输入一个数字:"
Label2.FontSize = 72
Label2.AutoSize = True
Label2.ForeColor = vbRed
Command1.Caption = "比较大小"
End Sub
你在窗体上添加两上label文字框,一个text文本输入框,一个Command按钮,然后把上面的代码复制进去,运行看结果吧!!
运行结果如下图:
用计时器的那位:代码最前还要加一行:
On Error Resume Next
否则要出错
这是判断代码,可以放到timer控件中监控
if val(text1.text) < 50 then
text2.text = "小"
else
text2.text = "大"
end if
Private Sub Command1_Click()
If Val(Text1.Text) > 50 Then Text2.Text = "大"
If Val(Text1.Text) < 50 Then Text2.Text = "小"
End Sub
Private Sub Command1_Click()
If IsNumeric(Text1.Text) = False Then Exit Sub
If Text1.Text > 50 Then Text2.Text = "大"
If Text1.Text < 50 Then Text2.Text = "小"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub