1

in a UFT script (formerly QTP) I am trying to change the locale to a given value before starting script execution. Our scripts run on virtual machines, which sometimes have different locales defined which results in errors being reported (eg different date formatting). By setting the locale at he start of the script, I want to avoid these errors.

I know how to change the locale in the script, this is pretty straightforward:

        If Currentlocale <> 2057 Then
            SetLocale "2057"
        End If

If I include this code into my UFT script, the locale is changed at runtime into 2057 and remains so until the script has finished. Perfect! We have dozens of scripts though, so I do not want to have to include this piece of code in every single script.

Each script has to login though, the login procedure resides as a single function in a function library which is linked to all these scripts. If I include the simple code into that single login function, what I see is : locale is changed when the login procedure is being executed (so, when you are in the login function), but as soon as the login procedure was executed and the script does the next step, the locale goes back to the original. So, looks like the function library doesn't pass on the new locale to the script as soon as the login function was executed. If you know what I mean ...

Any suggestions how to fix?

CompuMark
  • 11
  • 2

1 Answers1

0

Yes, you can. The beginning of your test using SetLocale(lcid) (or other appropriate location) is this:

SetLocale("en-gb") ' sets locale to UK 
SetLocale("en-us") ' sets locale to US 
SetLocale("de") ' sets locale to Germany 

https://admhelp.microfocus.com/uft/en/all/VBScript/Content/html/882ca1eb-81b6-4a73-839d-154c6440bf70.htm

To change the locale we can also play with the registry as well... Change the system Region/Location setting using vbs

Satish
  • 11
  • 3
  • Thanks, but this doesn't help. I am aware of the syntax you provide (actually SetLocale "en-gb" is the same as SetLocale "2057" which I already mentioned...). The registry hack is also not a solution as it requires a reboot, which is not possible while the script is running (script will have to be stopped in that case, which I don't want. Change should be 'on the fly' ...). – CompuMark Oct 15 '19 at 06:24