Sunday, June 19, 2011

A Function : Number or Characters filter


Use in Modual :

Option Explicit

Public Const gstrNUMERIC_DIGITS As String = "0123456789"
Public Const gstrUPPER_ALPHA_PLUS As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ,'-"

Public gblnPopulating As Boolean
Public Function ValidKey(pintKeyValue As Integer, _
pstrSearchString As String) As Integer '------------------------------------------------------------------------

' Common function to filter out keyboard characters passed to this
' function from KeyPress events.
'
' Typical call:
' KeyAscii = ValidKey(KeyAscii, gstrNUMERIC_DIGITS)
'

If pintKeyValue < 32 _
Or InStr(pstrSearchString, Chr$(pintKeyValue)) > 0 Then
'Do nothing - i.e., accept the control character or any key
' in the search string passed to this function ...
Else
'cancel (do not accept) any other key ...
pintKeyValue = 0
End If

ValidKey = pintKeyValue

End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
Call ValidKey(KeyAscii, gstrNUMERIC_DIGITS)
End Sub

इस function मे मुझे एक problem नजर आई | copy past करने पर कोई भी तरह कि value text box मे fill कर सकते है
function मे Error handling आपनी सुविधा के अनुसार coding करे |

1 comment: