PDA

Click to See Complete Forum and Search --> : Time_Zone_Information Structure Standard Name to a label


Trimbel
Jun 30th, 2000, 06:15 AM
Hey guys, this is probably an easy fix but I have no idea how to do it.....

I want to place the StandardName from the TIME_ZONE_INFORMATION Structure into a label.Caption

The example from the Windows API Guide for the GetTimeZoneInformation Function is as follows...

' Display the name of the time zone the computer is set to.

' receives information on the time zone
Dim tzi As TIME_ZONE_INFORMATION
' return value
Dim retval As Long
' counter variable needed to display time zone name
Dim c As Long

' read information on the computer's selected time zone
retval = GetTimeZoneInformation(tzi)
' Oddly, instead of being stored in a string, the time zone ' name is stored in a 32-element array, each element holding ' the ASCII code of one of the characters.
' This loop converts the array into a readable string.
Debug.Print "The computer's time zone is: ";
' the array's range is from 0 to 31

For c = 0 To 31
' abort if the terminating null character is reached
If tzi.StandardName(c) = 0 Then Exit For
' convert the ASCII code into a character and display it
Debug.Print Chr(tzi.StandardName(c))
Next c

' end the line being displayed
Debug.Print ""

Well thats the example code. If you have any ideas as how to put it in a label.Caption instead of the immediate window I would be very grateful for the help.

QWERTY
Jul 2nd, 2000, 10:57 PM
Change the line which says:

Debug.Print Chr(tzi.StandardName(c))

to

Label1.Caption = Label1.Caption & Chr(tzi.StandardName(c))

This will put the computer's time zone into the label. Make sure that the label's caption is set to "" before you start that operation. Otherwise you will it will be messed up.
HTH

Trimbel
Jul 3rd, 2000, 02:40 AM
Thankyou,thankyou, thankyou :)

I Added the code as you suggested and it works correctly for StandardName. i.e. it prints "AUS Eastern Standard Time" in the label.

Unfortunately when testing it for DaylightName it prints
"S Eastern Daylight Time"

For some reason the array does not store the first 2 character ascii codes for the string
"AUS Eastern Daylight Time"

It is a little strange but appears to have nothing to do with my program (does the same with the debug.print command)
or your help with it.

Thank you again for helping me