Click here to Skip to main content
16,012,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code in VB.NET 2008 and it works :-D
as the result, i can input starts from 1.00 until 99.99 :cool:

but i need more than this X|
i want the textbox automatic validate the input as i typed in the textbox :-\

example: i typed "1000" then the textbox will write "1,000"
i typed "10000.99" then the textbox will write "10,000.99"
nb: it has to disabled from typing ","

Please help me....!!!! S.O.S....... :omg: :omg:


VB
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    e.Handled = Percent(TextBox1, sender, e.KeyChar)
End Sub

Public Function Percent(ByVal tb As TextBox, ByVal sender As System.Object, ByVal eChar As Char) As Boolean
    Dim str As String = tb.Text & eChar
    If Val(str) <= 100 Then
        Dim c As Char = Globalization.NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator
        Dim chkstr As String = "0123456789" & c
        If chkstr.IndexOf(eChar) > -1 OrElse eChar = vbBack Then
            If tb.Text = "" And chkstr.IndexOf(eChar) = 0 Then
                Return True
            ElseIf tb.Text = "" And chkstr.IndexOf(eChar) = 10 Then
                Return True
            Else
                If eChar = c Then
                    If CType(sender, TextBox).Text.IndexOf(eChar) > -1 Then
                        Return True
                    Else
                        Return False
                    End If
                Else
                    Dim tt As Integer = InStr(tb.Text, c, CompareMethod.Text)
                    Dim ts As String = Microsoft.VisualBasic.Mid(tb.Text, tt + 1, tb.Text.Length - tt)
                    If tt = 0 Then
                        Return False
                    Else
                        If ts.Length >= 2 Then
                            If eChar = vbBack Then
                                Return False
                            Else
                                Return True
                            End If
                        Else
                            Return False
                        End If
                    End If
                End If
                Return False
            End If
        Else
            Return True
        End If
    Else
        If eChar = vbBack Then
            Return False
        Else
            Return True
        End If
    End If
End Function
Posted

1 solution

Google/CP Search for Masked textbox.

You need to make a custom control or say enhanced textbox control that can do all this for you.
 
Share this answer
 
Comments
siang_wu_id 21-Oct-10 4:13am    
how? help me please...
Sandeep Mewara 21-Oct-10 4:34am    
Google 'Masked textbox'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900