Results 1 to 12 of 12

Thread: Bug in VB6 when decimal and digit grouping symbols match?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2016
    Posts
    230

    Bug in VB6 when decimal and digit grouping symbols match?

    Hello

    If a user goes into Windows Region Settings and sets the decimal separator to a period for both numbers and currency, and sets the digit grouping symbol also to a period for both numbers and currency, Windows does not complain. One is to assume that this is a valid combination.

    However, if one sets a string to the result of FormatCurrency and then tries to do anything with that string, VB6 spits out a type mismatch.

    Code:
    Dim s As String
    Dim l As Long
    Dim c As Currency
    
    s = "1234567890.1234"
    Debug.Print "s: " & s
    ' s: 1234567890.1234
    l = CLng(s)
    Debug.Print "l: " & l
    ' l: 1234567890
    c = CCur(s)
    Debug.Print "c: " & c
    ' c: 1234567890.1234
    Debug.Print "FormatCurrency(c): " & FormatCurrency(c)
    ' FormatCurrency(c): UGX 1.234.567.890.12
    
    s = FormatCurrency(s)
    Debug.Print "s: " & s
    ' s: UGX 1.234.567.890.12
    l = CLng(s)
    ' Run-time error 13: Type mismatch
    ' Step over
    Debug.Print "l: " & l
    c = CCur(s)
    ' Run-time error 13: Type mismatch
    Debug.Print "c: " & c
    Debug.Print "FormatCurrency(c): " & FormatCurrency(c)
    If one were to do the same as above using a period as a decimal symbol and a comma as a digit grouping symbol, no issues. I'll paste just the output:
    Code:
    s: 1234567890.1234
    l: 1234567890
    c: 1234567890.1234
    FormatCurrency(c): UGX 1,234,567,890.12
    s: UGX 1,234,567,890.12
    l: 1234567890
    c: 1234567890.12
    FormatCurrency(c): UGX 1,234,567,890.12
    Since Windows allows a combination of identical characters as both the decimal symbol and the grouping symbol, it feels wrong if I test for this in my program on start and abort loading with a user-friendly warning if that is the case, but this seems to be the only choice if the program needs to be able to accept locale-formatted input from textboxes which will be converted to currency.

    Is this a VB6-only bug (I'm on Windows XP SP3)? Can you reproduce it in newer Windows? Can you reproduce it in .Net?

    What are your thoughts on this?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    Since Windows allows a combination of identical characters as both the decimal symbol and the grouping symbol
    Replacing some alpha characters in the English alphabet with non-alpha characters is allowed too. Just because it is allowed doesn't make it worthwhile trying to compensate for if it is wrong. We have a word for it: corrupted.

    Unless you know of a valid country/region that allows the same character for both decimal and grouping, I'd consider the data invalid, corrupted and not try to 'fix' it. But that's just my opinion.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    Those symbols are meant to be output formatting symbols.

    If you try to feed such strings into Windows' number parsing routines you have to expect trouble.

    I suspect VB6 makes use of VariantChangeType which probably makes use of VarParseNumFromStr and friends. The VB6 runtime might have its own code to do this but I can't imagine why they'd have duplicated the logic.

    So if anything this is a "Windows bug" if it is any kind of "bug" at all rather than simply misuse.

    And Windows XP has been dead and considered unsafe for over 3 years. Stop running it as soon as possible, it is a "zero-days forever" hazard to the entire Internet.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    And for a bit of clarification on my first reply. I'm not suggesting that it be ignored, just because it is the easy route to take. I'm suggesting that because it should be considered invalid data. If you were to attempt to 'fix' it, are you fixing otherwise valid data?

    For example, lets say you get a value like 123.456.789
    How do you know that 789 is the decimal portion or 123.456.789 is the entire whole number? How do you know that the real value wasn't 123.456.789,00123 and the value was improperly truncated by some process?

    But your original post talks about currency. One wouldn't expect decimal count greater than 2 numerals, i.e., .02 for 2 cents. However, that's not always the case as currency can exceed two numerals.

    In either case, attempting to fix improperly formatted data can always lead to errors. Errors can have a snowball effect, especially with currency and calculating balances, etc. I'm a fairly strong believer in aborting the processing of bad data unless it can be fixed with an extremely high percentage of confidence.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Addicted Member
    Join Date
    Sep 2015
    Posts
    225

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    I have a multi language app which I faced many problems regarding the decimal point, I always use Val() function to keep everything in a correct format and value!

  6. #6
    Addicted Member
    Join Date
    Sep 2015
    Posts
    225

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    Actually I was pulling my hair off of customers from Russia, China, Turkey and even France "Claiming" (I thought they were claiming) that the software is not accurate and giving wrong and magic results!!

    I installed a virtual machine that simulate their regional settings and I saw wonders
    From there I find out that my last resort is the Val() function.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    Val() is an old function only retained for compatibility with ancient Microsoft Basics. It is locale-blind and always uses the Invariant Locale, i.e. U.S. English, and returns a Double value.

    It has uses but should normally be avoided. Feed the wrong thing in (like a String formatted for Germany) and you can get wildly incorrect results with no error.

    This is called malpractice.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    If you want to work in Invariant Locale then do it. You can use something like:

    VConvert, A Class for Locale-Specific Data Conversions

    Just don't expect much if you have cobbled together inconsistent settings (like the period to mean multiple things).

  9. #9
    Addicted Member
    Join Date
    Sep 2015
    Posts
    225

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    Quote Originally Posted by dilettante View Post
    Val() is an old function only retained for compatibility with ancient Microsoft Basics. It is locale-blind and always uses the Invariant Locale, i.e. U.S. English, and returns a Double value.

    It has uses but should normally be avoided. Feed the wrong thing in (like a String formatted for Germany) and you can get wildly incorrect results with no error.

    This is called malpractice.
    I can't argue here, you're the boss.

    But it worked for me and made my life much easier for over 4 years till this moment and still counting
    Last edited by labmany; Oct 21st, 2017 at 10:58 PM.

  10. #10
    Addicted Member
    Join Date
    Sep 2015
    Posts
    225

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    Quote Originally Posted by dilettante View Post
    If you want to work in Invariant Locale then do it. You can use something like:

    VConvert, A Class for Locale-Specific Data Conversions

    Just don't expect much if you have cobbled together inconsistent settings (like the period to mean multiple things).
    Sure this will come in handy if it messed up with me, thanks dilettante

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 2016
    Posts
    230

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    I examined number and currency formatting standards used by all the countries I could find, and though I found many strange methods of notation I have never seen one where both symbols match.
    While most countries use something like "FOO 123 456 789.99" or "FOO 123,456,789.99", some use strange formats like "r. 123'456'789.12"

    LaVolpe I agree that such data should be considered invalid/corrupt. I go one step further by considering that such number and/or currency formatting should also be considered invalid/corrupt.

    I handled this by checking whether the decimal and digit grouping symbols for either numbers or currency are identical during program launch, and if they are then the launch is aborted and the user is presented with a user-friendly warning explaining the problem and how to navigate to Region settings to fix it.

    But your original post talks about currency. One wouldn't expect decimal count greater than 2 numerals, i.e., .02 for 2 cents. However, that's not always the case as currency can exceed two numerals.
    Common folk wisdom claims that the Generally Accepted Accounting Principles (GAAP) claim that one should store currency using four digits of precision (Decimal 19,4 in MariaDB). I call it folk wisdom because though I found various third-party sources making this claim, I have not yet been able to find a single official GAAP source stating that.
    Regardless, it makes sense to store currency amounts with a precision of more than two decimal places.

    dilettante I develop using a patched and isolated Windows XP installation in a virtual machine under Linux, mostly because it's tiny, but also because the software is used in various third-world countries who mostly still run Windows XP and that won't change any time soon, and developing on the same system is a good way of ensuring compatibility and discovering those crazy 90s Windows bugs and idiosyncrasies.

    Those symbols are meant to be output formatting symbols.
    If you try to feed such strings into Windows' number parsing routines you have to expect trouble.
    Two years of testing in various countries have shown that if the user's computer has sane number and currency formatting (a requirement for this program), then trouble is not to be expected.
    If the user is presented with a price for editing, I think it is helpful to use FormatCurrency to make the expected format clear:
    Code:
    textBox1.text = FormatCurrency(price)
    Would you present an editable currency amount to the user any differently?
    Last edited by OldClock; Oct 22nd, 2017 at 09:21 AM.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Bug in VB6 when decimal and digit grouping symbols match?

    I examined number and currency formatting standards used by all the countries I could find, and though I found many strange methods of notation I have never seen one where both symbols match.
    Wouldn't expect anything less. The written language is used to pass information/ideas. Using the same character for grouping/decimal (without some other rule/tiebreaker) would defeat that purpose -- information not passed concretely; audience would need to guess.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width