Print Page | Close Window

[SOLVED] Format Currency

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=14461
Printed Date: 21 November 2024 at 10:55pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: [SOLVED] Format Currency
Posted By: Aaron
Subject: [SOLVED] Format Currency
Date Posted: 06 June 2009 at 12:42pm
Hi,
 
I'm trying to format a currency value and it would be nice if the values in column currency looks like this:  
 
          �        12,10
          �   1.112,10  
          �      322,10
          �   9.112,10  
          ---------------
          � 10.558,40
         
 
The red marked characters are important for me (dots, commas, euro sign and 2 decimal places)
When editing item (for example) �        00,00     > user would enter: 12,1 and output would be:                �        12,10     in reportitem
 
Is this possible at all? Is there anyone who used this ever? If so I would like a working sample
 
Thanks a lot in advance.
 
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....



Replies:
Posted By: jpbro
Date Posted: 07 June 2009 at 10:16am
Hey Aaron,

I've recently coded some generic routines that let you format numbers to arbitrary locales (and cnvert arbitrary locale numbers to VB6 currency or other numeric variables). For example, you can pass a VB currency variable to my function and choose the Currency symbol, grouping symbol, decimal symbol and decimal places (my functions use the GetCurrencyFormat and GetNumberFormat APIs). I don't know exactly how you would use these with the ReportControl specifically (I haven't used the RC too much yet), but if these are something you want I can post them here (and you could post your results of integrating the routines to work with the RC  )


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 07 June 2009 at 11:29am
Hi Jason,
 
It is worth trying... Maybe I can use Format property of ReportItem in a different way. Would be nice if I could solve this
 
Thanks a lot.
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: jpbro
Date Posted: 07 June 2009 at 3:31pm
[See post below for most recent code]

For everything to work as expected, you should treat all of the currency values that users type in to your program as strings formatted for an arbitrary (but pre-defined) locale, then convert those strings to currency values (using the ArbitraryLocaleNumberToCurrency function) for math functions, and then re-convert the results to arbitrary locale strings using the FormatMoney function when displaying them to the user. This will allow you to use currency formatting for locales other than the users current locale (and without requiring them to change regional settings just to use currencies and formats for different locales).

If you find any problems with the code, please get back to me.



-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 08 June 2009 at 1:46pm
Hi Jason,
 
Can you upload code as a file?
 
Thanks
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: jpbro
Date Posted: 08 June 2009 at 2:42pm
See Post Below For Most Recent Code


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 09 June 2009 at 2:37pm
Hi Jason,
 
It doesn't format values like 0,10 or 0,3 or 1,20
 
Am I doing something wrong?
 
Thanks


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: jpbro
Date Posted: 09 June 2009 at 3:34pm
The test app should work like this:

1) Change the Grouping symbol to "."
2) Change the decimal symbol to ","
3) Type a number into the "User Locale Currency" (formatted to you current locale format as defined in your regional settings) and then click Convert. You should see something like this:




So the amount as originally typed must be in your current locale format so that CCur() can convert it to a VB6 Currency type. That value is then converted to an arbitrary locale format and returned as a string.

Or are you trying to accomplish something else?


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 09 June 2009 at 4:06pm
Hi Jason,
 
I have to format following values (for example)
 
    €    0,10
    €    0,30
    €    0,45
 
Just type these values into textbox and it will fail.
 
Thanks
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: jpbro
Date Posted: 09 June 2009 at 4:19pm
There could be a bug, but here is how it is supposed to work:

The textbox input has to be in the locale of your system as defined in the Regional Settings control panel. So if your number format is set to 1,234.55, then the input will have to be in that format.

If you want to use an arbitrary locale format for your input, you will have to use the ArbitraryLocaleNumberToCurrency() function on the input first (to convert it to a VB6 currency variable) and then pass that VB6 variable to the FormatMoney function for re-formatting. For example:

Regional Settings Number Format: 1,234.55
User Input in TextBox: 1.234,55
Send User Input to ArbitraryLocaleToCurrency("1.234,55", ".", ",", "") - Result = 1234.55 VB6 Currency Variable
Send Result of ArbitraryLocaleNumberToCurrency to FormatMoney(1234.55, decimal_Round, True, digitgrouping_Common, Chr$(128), ".", ",", True, False, negativestyle_Parentheses) Result = €1.234,55

if you regional settings are NOT set to "," grouping symbol and "." decimal symbol, then there is likely a bug and I will have to track it down.


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 10 June 2009 at 3:00pm
Hi Jason,
 
Did you look at the problem I mentioned? I looked in Regional Settings Number and format = 1.234,56
So I set Grouping and Decimal symbol same as above and when I enter value: 0,10 it fails
 
Thanks in advance

 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: jpbro
Date Posted: 10 June 2009 at 6:37pm
Hi Aaron,

Sorry about that, as I mentioned the code was only lightly tested so far. The problem stemmed from my misunderstanding of the Currency variable type in VB6. I thought that it would be internally stored with a "." for the decimal separator no matter what, but it appears that the implicit conversion to a string used the current locale format. The GetCurrencyFormat API requires the decimal separator to be a "."

I have modified the code (including an unrelated bugfix in the ConvertArbitraryLocaleNumberToUserLocale function), and this should be working now:

uploads/20090610_183606_MoneyFormat.zip - uploads/20090610_183606_MoneyFormat.zip


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 11 June 2009 at 12:48am
Hi Jason,
 
Now it works OK and it doesn't matter what the user enters (grouping / decimal character) it will format value as should, also with values that start with zero (0,21)
 
Thanks a lot
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: Aaron
Date Posted: 11 June 2009 at 3:50am

Hi,

Would be nice if CJ could implement this in ReportControl  
 
Format property removes all zero's after decimal character (1,20 will be 1,2)  and that's not what you want, if you are using currency values.
 
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....


Posted By: jpbro
Date Posted: 11 June 2009 at 7:26am
Glad to help Aaron, and sorry for the bugs.

-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: jpbro
Date Posted: 11 June 2009 at 8:44am
Also, thanks for helping me test it out in a different locale and reporting the bugs.

-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Aaron
Date Posted: 11 June 2009 at 10:29am
Hi Jason,
 
Well, now I know it will work also with different locale settings, you did that test for me
 
btw can you remove all code in previous replies (except the working code of course hehehe) so other user can see what code to use.
 
Thanks again.
 
 
 


-------------
Product: Xtreme SuitePro (ActiveX) version 15.0.2
Platform: Windows XP (32bit) - SP 2
Language: Visual Basic 6.0

Zero replies is not an option....



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net