一道vb编程题 在文本框1中输入一个正整数,在文本框1中按回车键表示结束输入,此时,在文本框2输出
答案:1 悬赏:20 手机版
解决时间 2021-02-14 20:36
- 提问者网友:浮克旳回音
- 2021-02-14 02:46
一道vb编程题 在文本框1中输入一个正整数,在文本框1中按回车键表示结束输入,此时,在文本框2输出
最佳答案
- 五星知识达人网友:毛毛
- 2021-02-14 03:49
Dim n As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
n = 0
Dim s As String
s = Text1.Text
For i = 1 To Len(s)
If Val(Mid(s, i, 1)) Mod 2 <> 0 Then
n = n + 1
End If
Next i
Text2.Text = n
End If
End Sub追问还有个不是正整数的情况没有追答Dim n As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1.Text) > 0 Then
n = 0
Dim s As String
s = Text1.Text
For i = 1 To Len(s)
If Val(Mid(s, i, 1)) Mod 2 <> 0 Then
n = n + 1
End If
Next i
Text2.Text = n
End If
Else
MsgBox "输入的不是一个正整数,请检查", vbOKOnly
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
n = 0
Dim s As String
s = Text1.Text
For i = 1 To Len(s)
If Val(Mid(s, i, 1)) Mod 2 <> 0 Then
n = n + 1
End If
Next i
Text2.Text = n
End If
End Sub追问还有个不是正整数的情况没有追答Dim n As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1.Text) > 0 Then
n = 0
Dim s As String
s = Text1.Text
For i = 1 To Len(s)
If Val(Mid(s, i, 1)) Mod 2 <> 0 Then
n = n + 1
End If
Next i
Text2.Text = n
End If
Else
MsgBox "输入的不是一个正整数,请检查", vbOKOnly
End If
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯