Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Currency Formats 1

Status
Not open for further replies.

rgh

Programmer
Feb 2, 2000
33
GB
Hi,

Is it possible to change the default currency at run time. Our user's regional settings are set up to be Sterling, however they want to use our system for 2 databases, one showing Sterling and one showing Dollar. Is is possible to change the default currency for the exe that is ran to show Dollar. I know I can do the following:

strCurrencyFormat = "$0.00" and then use

format (100.23,strCurrencyFormat)

however is it possible to still use

format (100.23,"Currency")

Thanks.

Richard.
 
It's a little tougher, but you can call
[tt]GetLocaleInfo()[/tt]
to find out how to format a currency for a specified LocaleID (LCID), and then set those values into a CurrencyFmt structure. Which you then save and reuse in calls to GetCurrencyFormat to reformat your values for display.

Chip H.
 
Thanks Chip - never would have got that myself.
 
I have coded the function below and I now use this to display fields with the currency symbol, however I run into another problem now. My current regional settings are "English(UK)" and when I change gstrCurrencySymbol to be $ everything displays fine, however when I do a ccur on any field that is displayed with a $ I get a type mismatch.

Do I have to code a function for ccur to handle the new currency symbol, or is there something else I need to do?

Cheers,

Richard.
-------------------------------------------------------
Public Function DisplayAsCurrency(ByVal curValue As Currency) As String

Dim strFormatted As String
Dim strLen As Long
Dim strSymbol As String
Dim intPos As Integer
With cft
.NumDigits = 2
.LeadingZero = 1
.Grouping = 3
.lpDecimalSep = "."
.lpThousandSep = ","
.NegativeOrder = 1
.PositiveOrder = 0
.lpCurrencySymbol = gstrCurrencySymbol
End With
strFormatted = Space(256)
strLen = GetCurrencyFormat(LOCALE_USER_DEFAULT, 0, curValue, cft, strFormatted, Len(strFormatted))
strFormatted = Left(strFormatted, strLen)
DisplayAsCurrency = strFormatted

End Function
 
RGH -

When you call CCur(), it looks for the current currency symbol for your locale (£) instead of the dollar sign ($).

What you might want to do is maintain two variables for each currency value you need - one for display purposes, and one for doing calculations. You've already got a function to go from the calculation version to the display version. To go in reverse, you'll need a function to strip all non-numeric characters (leave the decimal point, of course). The CCur() function will then function normally, since it's OK with a lack of a currency symbol.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top