我想在输入文字格式姓名时,对输入的非法字符和字母,进行报错,怎样做到?

解决方案 »

  1.   

    用if .......then ........语句来判断就行了
      

  2.   

    可以在Text1_Change事件中对字符进行判断
      

  3.   

    用text控件的change事件:
    查一下ASCAII码,把输入信息控制在你需要的范围内,如超出该范围即报错就可以了!!赶快试一下吧,祝你好运!
      

  4.   

    Private Sub TxtVendorID_KeyPress(KeyAscii As Integer)
        Call CheckoutNumber(KeyAscii, 1)
    End SubPublic Sub CheckoutNumber(TmpKeyascii As Integer, Mode As Integer)    'Mode 使用过程的方式,0 调用限制数字框 1 调用限制文本框 2 允许输入小数点
        If TmpKeyascii = 8 Then Exit Sub
        Select Case Mode
            Case 0
                If (TmpKeyascii < 48 Or TmpKeyascii > 59) And TmpKeyascii <> 13 Then
                    TmpKeyascii = 0
                End If
            Case 1
                If TmpKeyascii = 39 Then
                    TmpKeyascii = 0
                End If
            Case 3
                If (TmpKeyascii < 48 Or TmpKeyascii > 59) And TmpKeyascii <> 46 Then
                    TmpKeyascii = 0
                End If
        End Select
    End Sub
      

  5.   

    IF Then
    Else
    End If.
    楼上KeyPress事件中处理应该可以,报错放在Lost_Foucs事件中处理。