i want to format the text of the text box as integer without separator. Plz Help!
Printable View
i want to format the text of the text box as integer without separator. Plz Help!
without separator? I don't know what you mean by that, but try this:
Code:Dim myInteger As Integer = 0
If Integer.TryParse(TextBox1.Text, myInteger) Then
MsgBox("Success")
Else
MsgBox("Failure")
End If
you code isn't working as i want.
if i enter 1.00 then it is returning 'failure'. i want it to be formated as '1'. and if i enter 1.56 then it must be formated as '2'.
by separator i mean the commas in the number i.e 1,234,345,678.00
dim number as integer = ctype(math.round(ctype(TextBox1.Text, decimal)), integer)
what if the user enters characters in textbox1Code:dim number as integer = ctype(math.round(ctype(TextBox1.Text, decimal)), integer)
check it first with integer.tryparse
vb Code:
if integer.tryparse(ctype(math.round(ctype(TextBox1.Text, decimal)), integer), number) then number = ctype(math.round(ctype(TextBox1.Text, decimal)), integer) end if
1.00 is a decimal, not an integer..
Code:Dim myDecimal As Decimal = 1.57
If Decimal.TryParse(TextBox1.Text, myDecimal) Then
myDecimal = Math.Round(myDecimal)
MsgBox("Success")
Else
MsgBox("Failure")
End If