作业帮 > 综合 > 作业

VB编程题.输入一个整数判断他是否是5 的倍数

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/10 14:49:41
VB编程题.输入一个整数判断他是否是5 的倍数
VB编程题.输入一个整数判断他是否是5 的倍数
Private Sub CommandButton1_Click()
Dim nNum As Long
If IsNumeric(TextBox1.Text) Then
nNum = Val(TextBox1.Text)
If nNum Mod 5 = 0 Then
MsgBox "能被5整除!",vbInformation,"提示"
Else
MsgBox "不能被5整除!",vbInformation,"提示"
End If
Else
MsgBox "输入不正确!",vbExclamation,"提示"
TextBox1.SetFocus
End If
End Sub
再问: VB编程题。输入一个整数判断他是否是5 的倍数,要求文本框输入整数,由标签框输出判断结果!
再答: Option Explicit Private Sub Form_Load() Text1.Text = "" End Sub Private Sub Text1_Change() Dim nNum As Long If Text1.Text = "" Then Label1.Caption = "请输入一个整数!" Exit Sub End If If IsNumeric(Text1.Text) Then nNum = Val(Text1.Text) If nNum Mod 5 = 0 Then Label1.Caption = "能被5整除!" Else Label1.Caption = "不能被5整除!" End If Else Label1.Caption = "输入不正确!" End If End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 8 Then '可以退格 ElseIf KeyAscii >= 48 And KeyAscii