设计一个简易计算器,要实现如果在TEXT1里输入非数字,就提示“请输入数字,谢谢”然后焦点回到TEXT1上.。
我是新手~各位大大多多帮忙哈~谢谢!

解决方案 »

  1.   


    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    If Not IsNumeric(Chr(KeyCode)) Then MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
    End Sub
      

  2.   

    修改了一下,楼主试试看。Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 Then
        MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
    End If
    End Sub
      

  3.   

    刚才没留意,呵呵Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 Then
        MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
    End If
    End Sub
      

  4.   


    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii < 48 Or KeyAscii > 57 Then
            MsgBox "请输入数字,谢谢"
            Text1.SelStart = Len(Form1.Text1.Text)
            Text1.SetFocus
        End If
    End Sub
      

  5.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 Then
        MsgBox "请输入数字,谢谢": Text1.Text = "": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
    End If
    End Sub
    呵呵~谢谢各位~
      

  6.   

    刚刚在修改一下,这样就不能在一组数字出现超过一个小数点。Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 46 And 0 < InStr(Form1.Text1.Text, ".") Then KeyAscii = 0
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 13 And KeyAscii <> 46 And KeyAscii <> 0 Then
        MsgBox "请输入数字,谢谢": Form1.Text1.SelStart = Len(Form1.Text1.Text): Form1.Text1.SetFocus
    End If
    End Sub
      

  7.   


    Private Sub Form_Load()
       Text1 = ""
    End SubPrivate Sub Text1_Change()
       If Not IsNumeric(Text1) And Text1 <> "" Then
           Text1 = Left(Text1, Len(Text1) - 1)
           Text1.SelStart = Len(Text1)
           MsgBox "请输入数字,谢谢"
       End If
           
    End Sub