试编写一个完整的源程序,⑴检查从键盘输入的字符是否为数字0─9的字符。⑵如果是,在屏幕上显示“You have enter a number.”,返回操作系统;⑶否则在屏幕上显示“You have not enter a number!”, 重新回功能⑴。(程序开始用单个字符输入功能调用)

解决方案 »

  1.   

    强烈怀疑你这个题目是要写个QB或者C的程序.......
    Option ExplicitPrivate Sub Form_KeyPress(KeyAscii As Integer)
        If KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Then
            Form1.Print "You have enter a number."
        Else
            Form1.Print "You have not enter a number."
        End If
    End SubPrivate Sub Form_Load()
        Form1.AutoRedraw = True
    End Sub
      

  2.   

    在FORM的KeyPress属性中加入判断输入字符的ASCII码。
      

  3.   

    如果没有那个form不需要获取焦点的情况下就可以知道你按了什么键,这才有意思啊
      

  4.   

    Private Sub text1_keypress(KeyAscii As Integer)
      If Chr(KeyAscii) Like "[0-9]"  then
        Form1.Print "You have enter a number."
        Else
            Form1.Print "You have not enter a number."
        End If
    End SubPrivate Sub Form_Load()
        Form1.AutoRedraw = True
    End Sub
      

  5.   

    如果是在文本框中输入的话,可以这样:
    Private Sub Text1_Change()
        Dim i As Integer
        On Error GoTo L1
        i = Right(Text1.Text, 1)
        Print "You have enter a number"
       
        GoTo L2
    L1:
        Print "You have not enter a number"
    L2:
    End Sub