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

Currency symbol displays as question mark 2

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I need to display the Nigerian Naira currency symbol. I can paste this into control panel fine and Excel will then happily show any currency fields with the correct Naira symbol.

But the VB6 FormatCurrency function displays a "?" instead. Is this something to do with unicode and/or code pages and what might be done to rectify this please?

I am working in the UK but, for testing purposes I'm happy to drive this from control panel / locale selection.
 
VB6 is so old it was invented when they used shrunken heads for currency in Nigeria.
 
Maybe thread222-1552838 could help, it has a currency formatter, unicode msgbox and the LCID's of the differing locales.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post

 
Thanks, I had seen that thread but was hoping I could perhaps just find the right locale or control panel change to implement this.

If necessary I will change all the FormatCurrency calls to calls to my own function.

It's interesting that the Symbol dropdown in the Currency option of the DataFormat property has a shedload of symbol options but Naira is not one of them.
 
I'm just hazarding a guess from looking at the NLS link I provided in the other thread, but it doesn't look like the NLS API supported Nigerian until Windows Vista.

Could be wrong there though... [wink]

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post

 
Thanks again. I see where you're coming from but these Nigerian appearances in the Vista list are specific Nigerian languages. Really what I want to see is an "English (Nigerian)" option but I've not seen that anywhere. Even "English (Africa)" might help.
 
One of the big problems here is that the Naira only has a Unicode representation, there is no ANSI equivalent (most of the common currency symbols they have a UNICODE value that is mapped to an ANSI value). So you have two or three problems in VB

1) VB strings as seen by the user are not UNICODE
2) None of the standard VB controls are UNICODE-aware, so they cannot display UNICODE characters
3) Currently, only a few Windows fonts contain the necessary character (basically those fonts that contain the complete UNICODE character set), so even if VB and its controls knew about UNICODE you'd still see the wrong character if you were not using the correct font.

But we can work around most of these to greater or lesser affect.

Here are two functions (the second of which is a minor reworking of one of the examples that HarleyQuinn presented in the thread he linked to above, and assumes that you have modified your current country settings to use the Naira) that generate the necessary UNICODE string (i.e we deal with problem 1):
Code:
[blue]Private Declare Function GetCurrencyFormatW Lib "kernel32" (ByVal locale As Long, ByVal dwFlags As Long, ByVal lpValue As Long, lpFormat As Any, ByVal lpCurrencyStr As Long, ByVal cchCurrency As Long) As Long
Private Const LOCALE_NOUSEROVERRIDE As Long = &H80000000

[green]' returns UNICODE string in byte array[/green]
Public Function NigerianCurrency(CurrencyVal As Variant) As Byte()
    Dim tempstring As String
    
    tempstring = Chr$(166) & Chr$(32) & StrConv(Format(CurrencyVal, "0.00"), vbUnicode)
    NigerianCurrency = tempstring
End Function

[green]' returns UNICODE string in byte array[/green]
Function GetCurrency(expression As Variant) As Byte()
    Dim ret As Long
    Dim stBuffer As String
    ret = GetCurrencyFormatW(0&, 0&, StrPtr(CStr(expression)), ByVal 0&, 0&, 0&)
    stBuffer = String$(ret, vbNullChar)
    ret = GetCurrencyFormatW(0&, 0&, StrPtr(CStr(expression)), ByVal 0&, StrPtr(stBuffer), Len(stBuffer))
    GetCurrency = StrConv(Left(stBuffer, ret - 1), vbUnicode)
End Function[/blue]

And here are a couple of methods of actually displaying the result correctly, one on a VB From, the other on a UNICODE-aware MessageBox. Note that the declarations here are not the ones you get from the API text viewer, since those are the ANSI versions:
Code:
[blue]Private Declare Function MessageBox Lib "user32" Alias "MessageBoxW" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutW" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long


Private Sub Command1_Click()
    MessageBox 0, NigerianCurrency(2.9), StrConv("Example", vbUnicode), 0
    MessageBox 0, GetCurrency(2.9), StrConv("Example2", vbUnicode), 0
End Sub

Private Sub Command2_Click()
    Form1.Font = "Arial Unicode MS"
    Form1.FontSize = 10
    Dim displaytext() As Byte
    displaytext = NigerianCurrency(2.9)
    TextOut Form1.hdc, 0, 0, displaytext, UBound(displaytext) / 4
    displaytext = GetCurrency(2.9)
    TextOut Form1.hdc, 0, 10, displaytext, UBound(displaytext) / 4
End Sub[/blue]



 
Thanks for going into such detail strongm.

That will prove very useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top