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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting foreign currenct???

Status
Not open for further replies.

gbfell

Programmer
Dec 11, 2001
27
0
0
US
We are developing software that allows the user to choose their currency type. we then need to format all currency fields in the program like the type chosen. here is the hitch, we can NOT look at the regional settings, we have to ignore them. so, a user could have english regional setting, but in our software choose icelandic for example, and we need all of the currency fields to be icelandic.

any thoughts???
 
One way is to store your 'currency' fields as numbers (doubles). Then use manual formatting to display your numbers in your app. This will allow you to do any math calculations that are required and control the way the currency values are displayed to the user.

I would do something like this.

text1=format(value,&quot;<symbol>#,###,##0.00&quot;)
text1=<symbol> & format(value,&quot;# ### ##0.00&quot;)

You can play with the format command to get it to display the way you want. Thanks and Good Luck!

zemp
 
1.User selects format and the format ID sets a global variable with the format string:

Global gCurrencyFormat As String

gCurrencyFormat = &quot;#.###.##0,00&quot; 'User comma as decimal seperator

Then, wherever you display a currency value, you just format if first:

Text1.Text = Format$(dCurrencyValue,gCurrencyFormat)

However, you may have problems working with user input values. If the system is set using a dot as a decimal seperator, and the user enters a comma, then you will need to convert back before you do calculations or save in a Db:

Dim sUserInput As String
sUserInput = Text1.Text
sUserInput = Format$(sUserInput,&quot;#,###,##0.00&quot;
If IsNumeric(sUserInput) then
dCurrencyValue = CDbl(sUserInput)
Else
MsgBox &quot;Bad Input&quot;
End IF

Therefore, the best way is to create a function to take care of this for you.
 
Does anyone know a way to grab all of the different types of currency formats? Perhaps using an API call for example? If we could do that, we may be closer to our goal, because we could grab that and format it accordingly.
 
This will at least get you the Currency Symbol. I am sure that it would be easy to change for other regional settings.

Hope it helps,

hammy.

Option Explicit

Private Declare Function GetLocaleInfo Lib &quot;kernel32&quot; _
Alias &quot;GetLocaleInfoA&quot; (ByVal Locale As Long, _
ByVal LCType As Long, ByVal lpLCData As String, _
ByVal cchData As Long) As Long
Private Declare Function GetUserDefaultLCID% Lib &quot;kernel32&quot; ()
Private Const LOCALE_SCURRENCY = &H14


Private Sub Form_Load()

Dim Symbol As String
Dim iRet1 As Long
Dim iRet2 As Long
Dim lpLCDataVar As String
Dim pos As Integer
Dim Locale As Long

Locale = GetUserDefaultLCID()
iRet1 = GetLocaleInfo(Locale, LOCALE_SCURRENCY, lpLCDataVar, 0)

Symbol = String$(iRet1, 0)
iRet2 = GetLocaleInfo(Locale, LOCALE_SCURRENCY, Symbol, iRet1)
pos = InStr(Symbol, Chr$(0))

If pos > 0 Then
Symbol = Left$(Symbol, pos - 1)
End If


End Sub
 
ok now we are able to format the number properly, but when we try to insert it into an access db, it wont take it. it will only accept values that are the same as your current regional settings. how can we do this? we'd like to be able to insert the values into a currency or number field without too much grief.
 
I stated:
>If the system is set using a dot as a decimal seperator, and the user enters a comma, then you will need to convert back before you do calculations or save in a Db....

So, you will need to it before saving.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top