The recent article about globalizing in VB.NET demonstrates how a number can be formatted there, but what about VB 6?
Veteran VB 6'er (and frequent co-author) Peter Zilahy Ingerman (Getting Your System Out, Calculating a Contrasting Color Code, and Symbolic Logic) read my article and passed along a trick that works for him.
First, note that VB 6 can automatically format a number according to the "Regional Option" set in Windows fairly easily. For example, if I set my system to "Slovenian" I can format a number using the Format function in VB 6 ...
Format(123456.78, "###,##0.00")
I then get
123.456,78
... in proper Slovenian form.
Peter said he often had a slightly different problem. "The issue arises in the context where ... I allow the user to *enter* numbers in a locale-specific way, so I have to parse them into my internal standard form." In other words, how do you figure out if the user entered, "123.456,78" or "123,456.78".
You can do this in VB 6 using API calls. The code,
Private Declare Function GetUserDefaultLCID% Lib "kernel32" ()
Private Sub Command1_Click()
Dim LCID As Long
'get the user's Locale ID
LCID = GetUserDefaultLCID()
End Sub
... will return an LCID value of 1060 for Slovenian and 1033 for United States English. You can then plug this into the GetNumberFormat Win32 API and get a value in a NUMBERFMT structure that can be interrogated to determine what the local number formatting culture is. No less an authority than Dan Appleman states in his landmark book, A Guide to the Win32 API, "This structure is tricky to use from Visual Basic." (And he doesn't give an example.)
Or ... you can use a simple two line code snippet in VB 6 that Peter suggests.
LocaleDecimal = Mid$(CStr(11 / 10), 2, 1)
LocaleComma = Chr$(90 - Asc(LocaleDecimal))
The variables LocaleDecimal and LocaleComma will contain the appropriate symbol according to the Windows setting after this code executes. The key to making this happen is to get Windows to give you a string with the appropriate formatting. If you have the region set to Slovenian (or any other area where comma is the decimal symbol), CStr(10 / 11) returns the string "1,1". In my testing, CStr(1.1) does too, but Peter felt that a division avoids a "circular definition" in the code.
The second line works because the ASCII value of a comma plus a decimal equal 90 in any culture. So if you subtract one, you get the other.
Cultural Values are great!

Hello Dan,
Please, allow me to note that I guess Peter Zilahy Ingerman to be of Hungarian origin. Although in your tutorial not a word is about his origin, but the “Slovanian form” has been indicating a sort of reference to Central Europe, as if unintentionally linked to Peter.
Well, as a kibitzer I may become rubuffed but even risking the chance, I reckon him to be a namesake of Lajos Zilahy, a writer of excellent literature values.
Besides, let me thank you for your tut, it is also worth of high merits.
That’s interesting! I’ve never talked to Peter about that. I don’t post email addresses in an open forum but I will alert Peter to your message and see if he wants to get in touch with you.
Although I don’t know if Peter is Slovenian, my wife is. (Her maiden name was “Matekovic”.) And I’m a real fan of Milovan Djilas. (I know, he’s Montenegran, not Slovenian.)
Antal has the right answer, but for the wrong reason!
When I was a freshman in High School (in the United States!) I was befriended by a senior named Michael Zilahy. He graduated, and died suddenly. I, at age 14 decided to adopt his surname as my middle name and, with the explicit permission of his father … yes, Lajos Zilahy … did so.
But my surname … Ingerman … comes from Ingermanland, a country that existed for about nine months in 1920, and whose native language is related to Finnish. So I’m kind of Finno-Ugric by descent/adoption, but definitely not Slavic.
Overall a very useful article, along w/ very interesting comments.