Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2008, 12:31 AM
Registered User
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default help me to change number format?

hai pro,
    i am using XP OS. i want to show the number format like "12,34,56,789.00". my code is text1 = formatnumber("123456789",2,vbTrue,vbTrue,vbTrue). my OS number format digit grouping is - '12,34,56,789.00'. But the code returning like this "123,456,789.00". what i need to do? is there any mistake in code. can any one help me?

 
Old April 7th, 2008, 03:59 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Hi,

The last parameter (GroupDig) needs to be set as default. This will give output based on delimiter specified in the computer's regional settings:

-2 = TristateUseDefault - Use the computer's regional settings
-1 = TristateTrue - True
0 = TristateFalse - False

Om Prakash
 
Old April 7th, 2008, 07:08 AM
Registered User
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by om_prakash
 Hi,

The last parameter (GroupDig) needs to be set as default. This will give output based on delimiter specified in the computer's regional settings:

-2 = TristateUseDefault - Use the computer's regional settings
-1 = TristateTrue - True
0 = TristateFalse - False

Om Prakash
Hi prakash,
   My problem is TristateUseDefault is not working.
text1 = 1212123

Private Sub Command1_Click()
Text1 = FormatNumber(Text1, 2, vbTrue, vbTrue, vbUseDefault)
End Sub

result is = 1212123.00
    What mistake in my code. please guide me.

harish



 
Old April 7th, 2008, 03:47 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It’s no help, but I’m curious: What is the meaning of that grouping for numbers? I have not seen this before.

Given the comments here, I suspect you will have to write a function yourself to do this. What you would do is
Convert the number to a string
Add ".00" to the end
Reverse the string.

Nex you will be reading a character at a time, then building a new string from what you find.

Add the first 6 characters to the new string ("00.321")
Add a comma
If there are two more characters, add them.
If there are more add a comma

Keep repeating that until you run out of characters.
Then reverse the new string and return it as the function’s value.
Then, starting with the first character
 
Old June 20th, 2008, 06:30 AM
Registered User
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Private Function FormatNum(Num As String, vformat As String) As String
    Dim str As String, tmpstr As String, tmpStr2 As String, i As Long
    str = format(Num, vformat)

    If InStr(str, ".") > 0 Then
        tmpstr = Mid(str, 1, InStr(str, ".") - 1)
        str = Right(tmpstr, 3) & Mid(str, InStr(str, "."))
    Else
        tmpstr = str
        str = Right(tmpstr, 3)
    End If

    tmpstr = Replace(Left(tmpstr, Len(tmpstr) - 3), ",", "")
    While Len(tmpstr) > 2
        tmpStr2 = Right(tmpstr, 2) & "," & tmpStr2
        tmpstr = Left(tmpstr, Len(tmpstr) - 2)
    Wend
    tmpStr2 = tmpstr & "," & tmpStr2

    FormatNum = tmpStr2 & str
End Function





Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Number Dink Classic ASP Databases 2 January 23rd, 2007 01:40 AM
Number Format - Need Help! bridog39 Access 7 November 14th, 2005 02:50 PM
Format Number hcweb Classic ASP Basics 4 October 27th, 2004 11:23 AM
format number tgopal Javascript 2 April 30th, 2004 03:44 AM
format-number NaN rbdave XSLT 1 October 23rd, 2003 06:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.