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:
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