siang_wu_id@yahoo.com
New member
- Joined
- Oct 14, 2009
- Messages
- 4
- Programming Experience
- 1-3
this is my code in VB.NET 2008 and it works 
as the result, i can input starts from 1.00 until 99.99
but i need more than this

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"
example: 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.......

as the result, i can input starts from 1.00 until 99.99
but i need more than this
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"
example: 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.......
VB.NET:
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
Last edited by a moderator: