'*******************************************************************'名称 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的按键
'作者 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的按键
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
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参数中
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
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