'*******************************************************************'名称     Sub_CheckNum
'作者   Morn Woo in 1998.10
'功能     检查键入的是否是数字(不允许负数)判断输入字符是否是数字,不是则释放字符
'参数     s(引用传递):待检查的字符串(如文本框中的文本);i(引用传递):字符的ASCII码.
'*******************************************************************Sub Sub_CheckNum(ByRef i As Integer, Optional ByRef s = "")
If Len(Trim(s)) Then
    Select Case i
       Case 48 To 57, 1 To 8, 11 To 13, 14 To 31, 46, 45
       Case Else
            Beep
            i = 0
    End Select
Else
   Select Case i
      Case 8, 48 To 57, 45
      Case 44:  If s = "" Then i = 0
      Case 46
         If InStr(s, ".") > 0 Then Beep: i = 0
      Case Else: Beep: i = 0
   End Select
 End If
End Sub
你改改把,要想不输入汉字的方法是释放 asc(keyascii)<0的按键

解决方案 »

  1.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
            Case 8:
            Case 48 To 57:
            Case 97 To 122:
            Case 65 To 90:
            Case Else: KeyAscii = 0
        End Select
    End Sub
      

  2.   

    你写一个函数用ASCII来限制只能输入字母和数字
      

  3.   

    function chkdata(intData as integer,optional strString as string="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")as integer
    chkdata=iif( instr(strstring,ucase(asc(intdata)))=0 ,0,intdata)
    end functionPrivate Sub Text1_KeyPress(KeyAscii As Integer)
       if not KeyAscii=13 then keyascii=chkdata(keyascii)
    End Sub差不多象上面的吧
    如果需要别的字符写在strstring参数中
      

  4.   

    4_Eye_Cat(没钱上网明天想戒网现在还是上网的四眼喵) 的方法很标准的,你可以放心用啊!!!!
      

  5.   

    只能输入数字.
    private declare function setwindowinglib"user32" alias"setwindowlong"(byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
    private declare function getwindowlong lib"user32" alias "getwindowlonga"(byval hwnd as long,byval nindex as ong) as long
     const ES_NUMBER=&2000&
     const GWL_STYLE=(-16)
    private sub controledit (thecontrol as control)
    dim x as long
    dim estyle as long
    estyle=getwindowlong(thecontrol.hwnd, GWL_STYLE)
    estyle=estyle or ES_NUMBER
    x=setwindowlong(thecontrol.hwnd,GWL_STYLE,estyle)
    end subprivate sub command1_click()
    call controledit(text1)
    end sub
      

  6.   

    只能输入数字.
    private declare function setwindowinglib"user32" alias"setwindowlong"(byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
    private declare function getwindowlong lib"user32" alias "getwindowlonga"(byval hwnd as long,byval nindex as ong) as long
     const ES_NUMBER=&2000&
     const GWL_STYLE=(-16)
    private sub controledit (thecontrol as control)
    dim x as long
    dim estyle as long
    estyle=getwindowlong(thecontrol.hwnd, GWL_STYLE)
    estyle=estyle or ES_NUMBER
    x=setwindowlong(thecontrol.hwnd,GWL_STYLE,estyle)
    end subprivate sub command1_click()
    call controledit(text1)
    end sub