Results 1 to 7 of 7

Thread: [2005] how to format as integer

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    [2005] how to format as integer

    i want to format the text of the text box as integer without separator. Plz Help!

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2005] how to format as integer

    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: [2005] how to format as integer

    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

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] how to format as integer

    dim number as integer = ctype(math.round(ctype(TextBox1.Text, decimal)), integer)

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: [2005] how to format as integer

    Code:
    dim number as integer = ctype(math.round(ctype(TextBox1.Text, decimal)), integer)
    what if the user enters characters in textbox1

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] how to format as integer

    check it first with integer.tryparse

    vb Code:
    1. if integer.tryparse(ctype(math.round(ctype(TextBox1.Text, decimal)), integer), number) then
    2.    number = ctype(math.round(ctype(TextBox1.Text, decimal)), integer)
    3. end if

  7. #7
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2005] how to format as integer

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width