VB 版 (精华区)
发信人: bloom (├┝┞┟┠┡┢┣), 信区: VB
标 题: 输入限制确认
发信站: 哈工大紫丁香 (2000年08月02日18:32:18 星期三), 转信
在某些应用程序中,我们需要限制在文本框或其它一些控件中只能输入数字或一些特定
的字符,现在我们可以通过下面的一个函数来实现此功能:
Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Bo
olean) As Integer
Dim ValidateList As String
Dim KeyOut As Integer
If Editable = True Then
ValidateList = UCase(ValidateString) & Chr(8)
Else
ValidateList = UCase(ValidateString)
End If
If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
KeyOut = KeyIn
Else
KeyOut = 0
Beep
End If
ValiText = KeyOut
End Function
在工程中加入此函数后,你就可以使用它了。方法:在需要限制输入的控件的 Key
Press 加入以下代码:
KeyAscii=ValiText(Keyascii, "0123456789/-",True)
现在你就可以过虑掉你不希望的字符了。在此例中,我们只接受第二个参数提供的
字符,即:"0123456789/-"
而此函数的第三个参数就决定了能否使用 [Backspace] 键。最后值得一提的是此函
数对大小写是不敏感的。
--
├┝┞┟┠┡┢┣ ※↑
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.233.140]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.950毫秒