Solved

How To :GetCurrencyFormat API

Posted on 1998-10-08
2
804 Views
Last Modified: 2008-01-16
I want to use the GetCurrencyFormat API in my VB 5 workspace.  I have Declared the API correctly, set up some variable declarations and I was wondering how I should initialize the arguements of this API in order for it to return the CURRENCYFMT structure with all filled members.  I am really looking for some sample ideas in how to make this function call work
0
Comment
Question by:pjd13
2 Comments
 
LVL 2

Accepted Solution

by:
BergJC earned 100 total points
ID: 1438838
I always used the GetLocaleInfo call to get that information:

Declarations:

Public Const LOCALE_USER_DEFAULT = &H400
Public Const LOCALE_SCURRENCY = &H14' local monetary symbol
Public Const LOCALE_SINTLSYMBOL = &H15' intl monetary symbol
Public Const LOCALE_SMONDECIMALSEP = &H16' monetary decimal separator
Public Const LOCALE_SMONTHOUSANDSEP = &H17' monetary thousand separator
Public Const LOCALE_SMONGROUPING = &H18' monetary grouping
Public Const LOCALE_ICURRDIGITS = &H19' # local monetary digits

Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Dim buffer As String * 100
Dim dl&

dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, buffer, 99)

dl& = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SMONTHOUSANDSEP, buffer, 99)

and so on...

Hope it helps...
0
 
LVL 14

Expert Comment

by:waty
ID: 1438839
Type CURRENCYFMT
      NumDigits As Long '  number of decimal digits
      LeadingZero As Long '  if leading zero in decimal fields
      Grouping As Long '  group size left of decimal
      lpDecimalSep As String              '  ptr to decimal separator string
      lpThousandSep As String             '  ptr to thousand separator string
      NegativeOrder As Long '  negative currency ordering
      PositiveOrder As Long '  positive currency ordering
      lpCurrencySymbol As String          '  ptr to currency symbol string
End Type


GetCurrencyFormat
The GetCurrencyFormat function formats a number string as a currency string for a specified locale.

int GetCurrencyFormat(
  LCID Locale,                  // locale for which currency string
                                // is to be formatted
  DWORD dwFlags,                // bit flag that controls the
                                // function's operation
  LPCTSTR lpValue,              // pointer to input number string
  CONST CURRENCYFMT *lpFormat,  // pointer to a formatting
                                // information structure
  LPTSTR lpCurrencyStr,         // pointer to output buffer
  int cchCurrency               // size of output buffer
);
 
Parameters
Locale
Specifies the locale for which the currency string is to be formatted. If lpFormat is NULL, the function formats the string according to the currency format for this locale. If lpFormat is not NULL, the function uses the locale only for formatting information not specified in the CURRENCYFMT structure (for example, the locale's string value for the negative sign).
This parameter can be a locale identifier created by the MAKELCID macro, or one of the following predefined values: LOCALE_SYSTEM_DEFAULT Default system locale.
LOCALE_USER_DEFAULT Default user locale.



dwFlags
A bit flag that controls the operation of the function. If lpFormat is non-NULL, this parameter must be zero.
If lpFormat is NULL, you can specify the LOCALE_NOUSEROVERRIDE flag to format the string using the system default currency format for the specified locale; or you can specify zero to format the string using any user overrides to the locale's default currency format.

lpValue
Points to a null-terminated string containing the number string to format.
This string can contain only the following characters:

Characters '0' through '9'
One decimal point (dot) if the number is a floating-point value
A minus sign in the first character position if the number is a negative value
All other characters are invalid. The function returns an error if the string pointed to by lpValue deviates from these rules.

lpFormat
Pointer to a CURRENCYFMT structure that contains currency formatting information. All members in the structure pointed to by lpFormat must contain appropriate values.
If lpFormat is NULL, the function uses the currency format of the specified locale.

lpCurrencyStr
Points to a buffer to receive the formatted currency string.
cchCurrency
Specifies the size, in bytes (ANSI version) or characters (Unicode version), of the lpCurrencyStr buffer. If cchCurrency is zero, the function returns the number of bytes or characters required to hold the formatted currency string, and the buffer pointed to by lpCurrencyStr is not used.
Return Values
If the function succeeds, the return value is the number of bytes (ANSI version) or characters (Unicode version) written to the buffer pointed to by lpCurrencyStr, or if the cchCurrency parameter is zero, the number of bytes or characters required to hold the formatted currency string.

If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError may return one of the following error codes:

ERROR_INSUFFICIENT_BUFFER
ERROR_INVALID FLAGS
ERROR_INVALID_PARAMETER

Remarks
Windows CE: The Locale parameter is ignored and the system locale is always used. The Locale parameter should be set to LOCALE_SYSTEM_DEFAULT to ensure compatibility with future versions of Windows CE.

No flags are supported for the dwFlags parameter.

QuickInfo
  Windows NT: Requires version 3.5 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winnls.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
String Manipulation Overview, String Manipulation Functions, GetNumberFormat, CURRENCYFMT

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now