Forum Discussion

JaredBill's avatar
JaredBill
Occasional Contributor
13 years ago

Help with VBscript - Time Related

Hello,  (Thank you in advance!)



I am having trouble with a VBscript that I'm writing.  I am automating a testcase and the scenario calls for me to change my regional settings mid way through the test.  What I believe is happening is that my regional settings are not getting reset correctly.  Let me explain in sudo code:



'To start I set regional settings to English

SetRegionalSettings("English (United States)")   

at this point I grab the system time using Now( )  ' **Point of failure on second run**  I expect this to be in English MM/DD/YYYY HH:MM:SS AM/PM



'I then do some things in my script and change regional settings

SetRegionalSettings("English (United Kingdom)")



'I do some more things and then at the end of the test I set it back to English

SetRegionalSettings("English (United States)")   



The problem I'm facing is that after running this script a number of times I've noticed that my time format is not getting restored to English properly.  So lets say I've ran the script once and everything is fine, I then run it again.  If you note the point above where it fails, what i'm seeing is that Now () is returning MM/DD/YYYY MilitaryTime.



Via a google search I found this link which explains that the Now() function uses the regional settings which the user has, so why isn't it returning the correct time?  Link Mentioned: http://support.microsoft.com/kb/218964



Additional Info:



Code used to switch Regional Settings:

'--------------------------------------------

'Subroutine: SetRegionalSettings

'Purpose: This Subroutine will set your computers regional settings to whatever

'         you want them to be.        

'Inputs: Region of you choice, must be a string which is identical to the choice

'        in the drop down.  Ex: "English (United Kingdom)"  Or

'        "English (United States)"

'Output: N/A

'--------------------------------------------

Sub SetRegionalSettings(Region)

      'Open regional settings

      Set sa = CreateObject("Shell.Application")

      sa.ControlPanelItem("Intl.cpl")

      aqUtils.Delay(3000)

    

      'Set value and save

      Call Aliases.rundll321.dlgRegionalAndLanguageOptions.page32770.ComboBox.ClickItem(Region)

      aqUtils.Delay(100)

      Call Aliases.rundll321.dlgRegionalAndLanguageOptions.page32770.Keys("[Tab]")

      aqUtils.Delay(500)

      Aliases.rundll321.dlgRegionalAndLanguageOptions.Window("Button", "OK", 1).ClickButton

      aqUtils.Delay(3000)

End Sub