Results 1 to 9 of 9

Thread: [RESOLVED] [2005] format question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Resolved [RESOLVED] [2005] format question

    why I set the format to 0000, but it doesn't work?
    here is my code
    Code:
    Dim loud As Integer
    loud = TextBox1.Text
    loud = Format(loud, "0000")
    console.writeln(loud)
    if my textbox1 is 0123, it just show me 123...

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] format question

    Code:
    Dim loud As Integer
    If Integer.TryParse(TextBox1.Text, loud) Then
        Debug.WriteLine(loud.ToString("0000"))
    Else
        Debug.WriteLine("Invalid number")
    End If

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: [2005] format question

    so, is that right?
    loud = loud.tostring("0000")

  4. #4
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] format question

    Nevermind, stanav beat me to the punch.

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  5. #5
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] format question

    Quote Originally Posted by newpat
    so, is that right?
    loud = loud.tostring("0000")
    stanav gave you the solution you were asking for. Did you give it a shot?

    In addition, here is some more on formatting:
    http://msdn2.microsoft.com/en-us/lib...sy(VS.80).aspx

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: [2005] format question

    Quote Originally Posted by stanav
    Code:
    Dim loud As Integer
    If Integer.TryParse(TextBox1.Text, loud) Then
        Debug.WriteLine(loud.ToString("0000"))
    Else
        Debug.WriteLine("Invalid number")
    End If
    but how can I save the 0123 to loud?
    I tried, although it come out with "0123", I dun know how can I save it to loud.

  7. #7
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] format question

    Integers do not have leading zeros. Save it to a string variable if you must have the leading zero.

    vb.net Code:
    1. ' loud    
    2.         Dim loud As Integer = 123
    3.         Dim str As String = loud.ToString("0000")
    4.  
    5.         MessageBox.Show(str)

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] format question

    Quote Originally Posted by newpat
    so, is that right?
    loud = loud.tostring("0000")
    No, that's not what I meant....
    What you have displayed on screen is just a string representation of the integer value. And you can not format an integer itself but rather its string representation. That's why you have to to convert the integer to string and then format that string.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: [2005] format question

    ok then...My integer is to compare with another integer...
    However, I have found out another way to do my expection.
    Thx for all!

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