|
-
Aug 28th, 2001, 09:45 AM
#1
Thread Starter
Addicted Member
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
-
Aug 28th, 2001, 09:55 AM
#2
Fanatic Member
Use the format function.
VB Code:
Private Sub Command1_Click()
MsgBox Format(1000000, "###,###,###")
End Sub
-
Aug 28th, 2001, 09:56 AM
#3
Thread Starter
Addicted Member
What if its an unknown random number. Would that still work?
Using:
Visual Studio .Net Enterprise
Visual Basic 6.0 Enterprise
-
Aug 28th, 2001, 09:58 AM
#4
Fanatic Member
Do you mean the value is contained in a variable?
VB Code:
Option Explicit
Dim lngNumber As Long
Private Sub Command1_Click()
lngNumber = 1000000
MsgBox Format(lngNumber, "###,###,###")
End Sub
-
Aug 28th, 2001, 10:05 AM
#5
Thread Starter
Addicted Member
Lets say would ###,###,### work with 1,000 100,000 or 1,000,000,000?
Using:
Visual Studio .Net Enterprise
Visual Basic 6.0 Enterprise
-
Aug 28th, 2001, 10:10 AM
#6
Fanatic Member
Yes. Actually it looks like you could do the following and it will place commas in the number.
VB Code:
Private Sub Command1_Click()
MsgBox Format(1000000000000#, "#,###")
End Sub
-
Aug 28th, 2001, 08:33 PM
#7
Thread Starter
Addicted Member
Using:
Visual Studio .Net Enterprise
Visual Basic 6.0 Enterprise
-
Aug 28th, 2001, 09:03 PM
#8
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|