写一个过程: Public Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) 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 Or KeyIn = 8 Then KeyOut = KeyIn Else KeyOut = 0 'MsgBox "非法字附" Beep End If ValiText = KeyOut End Function 用法: Private Sub Tx_fzlo_KeyPress(KeyAscii As Integer) SendTab KeyAscii KeyAscii = ValiText(KeyAscii, "1234567890.", False) End Sub
限制数字输入: Private Sub mebCardNum_KeyPress(KeyAscii As Integer) If ((KeyAscii = 8) Or (KeyAscii <= 57 And KeyAscii >= 48)) Then KeyAscii = KeyAscii Else KeyAscii = 0 Beep End If End Sub
限制数字输入: Private Sub mebCardNum_KeyPress(KeyAscii As Integer) If ((KeyAscii = 8) Or (KeyAscii <= 57 And KeyAscii >= 48)) Then KeyAscii = KeyAscii Else KeyAscii = 0 Beep '可以不要 End If End Sub
to:suhu
tx_fzl_KeyPress()中,只限数字录入。能说的具体些吗?
那可不行啊,怎么可以不管结果呢?
谁能帮我解决这个问题:tx_fzl_KeyPress()中,只限数字录入
Public Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) 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 Or KeyIn = 8 Then
KeyOut = KeyIn
Else
KeyOut = 0
'MsgBox "非法字附"
Beep
End If
ValiText = KeyOut
End Function
用法:
Private Sub Tx_fzlo_KeyPress(KeyAscii As Integer)
SendTab KeyAscii
KeyAscii = ValiText(KeyAscii, "1234567890.", False)
End Sub
1。SendTab KeyAscii 不懂!
2。ValidateList = UCase(ValidateString) & Chr(8)为何要这样做: &Chr(8)?
3.KeyAscii = ValiText(KeyAscii, "1234567890.", False),那么editable怎么会等于true?
Editable 是,控制是否可输入空格。
Private Sub mebCardNum_KeyPress(KeyAscii As Integer)
If ((KeyAscii = 8) Or (KeyAscii <= 57 And KeyAscii >= 48)) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
Beep
End If
End Sub
Private Sub mebCardNum_KeyPress(KeyAscii As Integer)
If ((KeyAscii = 8) Or (KeyAscii <= 57 And KeyAscii >= 48)) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
Beep '可以不要
End If
End Sub