Author : Raghuraja. C
Date Submitted : 2/17/2005
Category : Other
Compatibility : VB 6
This code has been accessed 3099 times.
Task : This function will allow only Currency in text boxed
Declarations
Code
'Please call this fn in Text box key press event
Private Sub txtCurency_KeyPress(KeyAscii As Integer)
KeyAscii = fnOnlyOrderCurrency(txtCurency, KeyAscii)
End Sub
'==================================
Public Function fnOnlyCurrency(objText As Object, intKP As Integer) As Integer
On Error GoTo LOCALERRORHANDLER
'To allow only Currency values 99999999.00
fnOnlyCurrency = intKP
If Len(objText.Text) > 12 Then
fnOnlyCurrency = 0
End If
If intKP = 8 Then
Exit Function
End If
If InStr(1, objText.Text, ".") <> 0 And intKP = 46 Then
fnOnlyCurrency = 0
ElseIf InStr(1, objText.Text, ".") <> 0 And (intKP > 47 And intKP < 58) Then
If Len(Mid(objText.Text, (InStr(1, objText.Text, ".") + 1))) >= 4 And objText.SelStart >= InStr(1, objText.Text, ".") Then
fnOnlyCurrency = 0
End If
Else
If (intKP > 47 And intKP < 58) Or intKP = 8 Or intKP = 46 Or intKP = 13 Then
Else
fnOnlyCurrency = 0
End If
End If
Exit Function
LOCALERRORHANDLER:
fnOnlyCurrency = 0
End Function