VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Text Box Currency Valiation code - Text box will allow only 9999.99

by Raghuraja.C (12 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Fri 28th February 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Text Box Currency Valiation code - Text box will allow only 9999.99

Rate Text Box Currency Valiation code - Text box will allow only 9999.99



'Place following code to form
Private Sub txtAmount_KeyPress(KeyAscii As Integer)

 
    If Len(txtAmount.Text) > 14 Then
        KeyAscii = 0
    End If

    If KeyAscii = 8 Then
        Exit Sub
    End If

    If InStr(1, txtAmount.Text, ".") <> 0 And KeyAscii = 46 Then
        KeyAscii = 0
    ElseIf InStr(1, txtAmount.Text, ".") <> 0 And (KeyAscii > 47 And KeyAscii < 58) Then
        If Len(Mid(txtAmount.Text, (InStr(1, txtAmount.Text, ".") + 1))) >= 2 And txtAmount.SelStart >= InStr(1, txtAmount.Text, ".") Then
            KeyAscii = 0
        End If
    Else
        If (KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = 8 Or KeyAscii = 46 Then
        Else
            KeyAscii = 0
        End If
    End If

End Sub

Download this snippet    Add to My Saved Code

Text Box Currency Valiation code - Text box will allow only 9999.99 Comments

No comments have been posted about Text Box Currency Valiation code - Text box will allow only 9999.99. Why not be the first to post a comment about Text Box Currency Valiation code - Text box will allow only 9999.99.

Post your comment

Subject:
Message:
0/1000 characters