Results 1 to 8 of 8

Thread: Adding commas to numbers

  1. #1

    Thread Starter
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217

    Adding commas to numbers

    How do I add commas to numbers so I can turn 1000 to 1,000 or 1000000 to 1,000,000.
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Use the format function.
    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox Format(1000000, "###,###,###")
    3. End Sub

  3. #3

    Thread Starter
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217
    What if its an unknown random number. Would that still work?
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Do you mean the value is contained in a variable?
    VB Code:
    1. Option Explicit
    2. Dim lngNumber As Long
    3.  
    4. Private Sub Command1_Click()
    5.     lngNumber = 1000000
    6.     MsgBox Format(lngNumber, "###,###,###")
    7. End Sub

  5. #5

    Thread Starter
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217
    Lets say would ###,###,### work with 1,000 100,000 or 1,000,000,000?
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  6. #6
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Yes. Actually it looks like you could do the following and it will place commas in the number.
    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox Format(1000000000000#, "#,###")
    3. End Sub

  7. #7

    Thread Starter
    Addicted Member Frankie902's Avatar
    Join Date
    Feb 2001
    Location
    Lindenwold, NJ, USA
    Posts
    217
    thanks
    Using:
    Visual Studio .Net Enterprise
    Visual Basic 6.0 Enterprise

  8. #8
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Matthew Gates' solution is preferable as it uses the group delimiter specified in the computer's regional settings, meaning it the code is portable to countries where the group delimiter is not a comma.

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