+ Reply to Thread
Results 1 to 15 of 15

VBA variables being set by language, how to convert to USA?

  1. #1
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Question VBA variables being set by language, how to convert to USA?

    I have an Excel application that is programmed in English (USA). I have a couple of users who use their system in Portuguese. When the app. is run on their machines REGARDLESS of the language setting they're using, the below variable sngBreak ALWAYS returns a value formatted in Portuguese, for example, if the cell contains 1.5 (language setting to English) the variable contains 1,5; if the cell contains 1,5 (language setting Portuguese) the variable still contains 1,5.

    Sample code:
    Please Login or Register  to view this content.

    I've tried the below code when the workbook opens and it doesn't affect the VBA variable settings:
    Please Login or Register  to view this content.
    This works visually in the spreadsheet cells just fine but it doesn't affect the internal VBA variable representation of the number. Also, so no one will mention it, trying to Replace commas with decimal points only affects the visual contents of the sheet i.e., it doesn't work, it's not a solution.

    How do I get the sngBreak variable to register its values as English? Is there a way to force Excel to run as English (maybe a solution)?
    ~Toby

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA variables being set by language, how to convert to USA?

    Hi,

    Untested, but does
    Please Login or Register  to view this content.
    do the trick?

    Rgds
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: VBA variables being set by language, how to convert to USA?

    Hi Toby,

    I didn't find an exact answer but got close on the net at:
    http://msdn.microsoft.com/en-us/library/b28bx3bh.aspx
    I'm thinking there should be a way to toggle languages from inside VBA.

    I may have to eat those words after I learn more about localization and global system settings.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA variables being set by language, how to convert to USA?

    if the cell contains 1.5 (language setting to English) the variable contains 1,5; if the cell contains 1,5 (language setting Portuguese) the variable still contains 1,5.
    I don't understand that, unless the number is stored as Text. Numeric values on the worksheet are always stored as Doubles, which is completely independent of language. Formatting is only for appearance.

    Try this:

    Please Login or Register  to view this content.
    What does that show in the Immediate window?
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: VBA variables being set by language, how to convert to USA?

    Quote Originally Posted by shg View Post
    I don't understand that, unless the number is stored as Text. Numeric values on the worksheet are always stored as Doubles, which is completely independent of language. Formatting is only for appearance.
    I think the reason is because her system boots up in Portuguese and not English.

    Quote Originally Posted by shg View Post
    Try this:

    Please Login or Register  to view this content.
    What does that show in the Immediate window?
    Thanks for the tips everyone. I'll try to get some time on her machine and play around some more. I'll keep you updated.

  6. #6
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: VBA variables being set by language, how to convert to USA?

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    Untested, but does
    Please Login or Register  to view this content.
    do the trick?

    Rgds
    Nope. I had tried that and variations of it.

  7. #7
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: VBA variables being set by language, how to convert to USA?

    Please Login or Register  to view this content.
    returns 5. Looking that up, it means a Double even though the variable is Dimensioned as a Single (the code isn't extensive and easy to check, trust me, it's set as a Single data type).

    Additionally,
    Please Login or Register  to view this content.
    returns 1.5
    Good, right? No. Because if put into a LET statement, like so:
    Please Login or Register  to view this content.
    the variable becomes 15
    Even wrapping the statement in CDBL() and VAL() doesn't work, the variable always returns a result of 1,5 e.g., in the immediate window ?sngBreak

    Her system does boot up in Portuguese. I have access to her system this afternoon and I'm going to try changing the boot up language to English (change the settings from the Language Bar) and see what that does.

  8. #8
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: VBA variables being set by language, how to convert to USA?

    Booting up in Portuguese or English doesn't matter. I tried it w/her machine and same issue. Other agents boot up in English and they aren't having the same issue...which is really odd. They are using a Portuguese keyboard.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA variables being set by language, how to convert to USA?

    Please Login or Register  to view this content.
    returns 5. Looking that up, it means a Double even though the variable is Dimensioned as a Single (the code isn't extensive and easy to check, trust me, it's set as a Single data type).
    ALL numbers stored on a worksheet are Doubles. You can convert them to anything you want in VBA, but when you write them back to the worksheet, the values are converted back to Doubles.

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: VBA variables being set by language, how to convert to USA?

    Might the problem be that the Version of Office in question is Portuguese and not English?

    Your other agents that have no problem possibly have English versions.

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VBA variables being set by language, how to convert to USA?

    @Marcol

    That's the correct answer.(one of those eggheads ?)

    And that implicates that you should be happy to find that comma in that cell: it means that the value is unaltered, although the appearance has. It will be treated as you intended (your 1.5 in US is equivalent to the European 1,5). So I wonder why should you want to change it ?



  12. #12
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: VBA variables being set by language, how to convert to USA?

    Quote Originally Posted by snb View Post
    @Marcol

    That's the correct answer.(one of those eggheads ?)

    And that implicates that you should be happy to find that comma in that cell: it means that the value is unaltered, although the appearance has. It will be treated as you intended (your 1.5 in US is equivalent to the European 1,5). So I wonder why should you want to change it ?
    Marcol,
    Thanks. Hmmm...the agent came from Brazil and I wonder if her system did as well. Should I have IT reinstall Windows but in English and not Portuguese? The other agents use the Windows language bar to toggle between English and Portuguese w/o issue (though I think they mainly stay in Portuguese).

    Snb,
    Well, I've never run into an issue like this so, uhm, well, the company I work for is based in the USA and uses English. A couple of our agents in the customer support team we have for Latin America are the ones having the issue (the Spanish agents don't have this issue). What brought this about was that the numbers are being fed to a Microsoft Access (English version) database table that is expecting numbers. When the Portuguese number - for example, 1,5 - is added to the string being sent, instead of six numbers there are seven numbers being sent since the comma is the field separator.

    Example:
    English 2 and 1.5 being sent, two fields expected by the database table:
    2,1.5
    Same data being sent but with Portuguese formatting:
    2,1,5
    See...three fields are "seen" by the table and not the expected two.

    Two things I haven't tried yet:
    .Range(...).NumberFormatLocal
    .Value2
    I don't think the first one will work since the local format would be Portuguese.

    Well, now that you know what I'm up against, suggestions for a fix? Maybe something at the database feeding end? I haven't had much time to dedicate to this as it's a low priority

    Shg,
    I did not know that, thanks!

  13. #13
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: VBA variables being set by language, how to convert to USA?

    Not really my field but it is possible that the Language Settings are only set for Portugese, try adding a second language to the settings, I think 3 settings is the max, I believe that more than this confuses Office.

    See if this link, and its' hyperlinks to other other pages, helps
    http://office.microsoft.com/en-us/of...001136389.aspx

    [EDIT]
    Perhaps I did make myself clear enough earlier.
    When I was refering to "Version of Office" I meant the installed version, not the options selected during or after installation.
    Some sources install strange choices of the product, based on cost to them, and dare I say even pirated versions.
    This can lead to unexpected results with language options.

    See this link for "Mixed language versions of the 2007 Office system"
    http://technet.microsoft.com/en-us/l...ffice.12).aspx
    Last edited by Marcol; 09-29-2010 at 12:57 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VBA variables being set by language, how to convert to USA?

    You can always use:

    Please Login or Register  to view this content.
    but it seems the listseparator is more a problem:

    Please Login or Register  to view this content.
    Last edited by snb; 09-29-2010 at 12:45 PM.

  15. #15
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Thumbs up SOLVED: Re: VBA variables being set by language, how to convert to USA?

    snb, I have to leave the separators as commas since a string is built that INSERTs or UPDATEs the database with the info.

    After staring at how the code is built it dawned on me that the places where I needed to pass a string I surrounded the data by a single quote. So, by changing my variable data types to String, adding a data check to replace an empty string with zero, I could export the .Formula of the cell contents and pass the data to my db as planned.

    Here's a snippet of what I did. First is to make the data types String instead of Single:
    Please Login or Register  to view this content.
    Get the .Formula of the cell. This is the magic that works; I'm not an Excel MVP so I'll let them explain how it works. Next, an empty string will create an error for this code so turn an empty string into a zero:
    Please Login or Register  to view this content.
    Then the rest of the code:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1