Search code examples
textboxvb6masking

Masking textbox to accept only 1 digit after decimal


I am using VB6 and I want to allow user to enter only one digit after decimal,
please help.


Solution

  • Put the code below in change event of textbox. I think "." point is used for decimal seperator. if "," coma is used, then change the point in the code with coma.

    Private Sub TextBox1_Change()
    Dim strA As String
    Dim intP As Integer
    
        strA = TextBox1.Text
        intP = InStr(1, strA, ".", vbTextCompare)
    
        If intP > 0 Then TextBox1.Text = Left(strA, intP + 1)
    End Sub