一道vb编程题 在文本框1中输入一个正整数,在文本框1中按回车键表示结束输入,此时,在文本框2输出

2025-05-19 22:51:55
推荐回答(1个)
回答1:

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