VictorC
October 17th, 2001, 02:10 AM
Can somebody help me?
I want to make a function in VBA that returns the GMT value. For example: Australie +11 and for Amsterdam +1.
Thanks for your time!
John G Duffy
October 17th, 2001, 08:33 AM
Are you asking for the offset from GMT or GMT itself or local time?
Http://www.Planet-Source-Code.com.vb has many examples of all this. You might scrounge around there for an appropriate example. If you can't find what you want, Repost with more details about what you are trying to do.
John G
VictorC
October 17th, 2001, 08:40 AM
I like to know the offset from GMT. I have looked at Http://www.Planet-Source-Code.com but I can't find what I'm looking for. I need the offset for some calculations in Excell. Can you help me?
John G Duffy
October 17th, 2001, 09:14 AM
Yes. I can help. Here is a sample program that does what you need.
1). Start a new project
2). Add 6 Labels (Label1-6) align one under the other
3). Next to each of these labels add a textbox
4). Name them thusly.
'
txtLocTime (next to Label1)
txtSysTime (next to Label2)
txtAdjust (next to label3)
txtTZBias etc
txtTZName etc
txtTZSname etc
'
5). Add a timer (Timer1)
6). Paste this code into the general declarations section of the form
7). Run it.
'
option Explicit
private Const LOCALE_SYSTEM_DEFAULT& = &H800
private Const LOCALE_USER_DEFAULT& = &H400
'**********************************
'** Type Definitions:
#If Win32 then
private Type SYSTEMTIME
wYear as Integer
wMonth as Integer
wDayOfWeek as Integer
wDay as Integer
wHour as Integer
wMinute as Integer
wSecond as Integer
wMilliseconds as Integer
End Type
private Type TIME_ZONE_INFORMATION
Bias as Long
StandardName as string * 64
StandardDate as SYSTEMTIME
StandardBias as Long
DaylightName as string * 64
DaylightDate as SYSTEMTIME
DaylightBias as Long
End Type
#End If 'WIN32 Types
'**********************************
'** Function Declarations:
#If Win32 then
private Declare Function GetLocaleInfo& Lib "kernel32" Alias "GetLocaleInfoA" (byval Locale as Long, byval LCType as Long, byval lpLCData as string, byval cchData as Long)
private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime as SYSTEMTIME)
private Declare Sub GetSystemTimeAdjustment Lib "kernel32" (lpTimeAdjustment as Long, lpTimeIncrement as Long, lpTimeAdjustmentDisabled as Long)
private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime as SYSTEMTIME)
private Declare Function GetTimeZoneInformation& Lib "kernel32" (lpTimeZoneInformation as TIME_ZONE_INFORMATION)
private Declare Function GetTimeFormat& Lib "kernel32" Alias "GetTimeFormatA" _
(byval Locale as Long, byval dwFlags as Long, lpTime as SYSTEMTIME, _
byval lpFormat as Long, byval lpTimeStr as string, byval cchTime as Long)
#End If 'WIN32
private Sub Form_Load()
Dim myTZ as TIME_ZONE_INFORMATION
Dim myAdj&, myIncr&, myDisabled&
Dim s$, dl&
Label1 = "Local time"
Label2 = "System time"
Label3 = "Adjustment"
Label4 = "time Diff"
Label5 = "Zone Name"
Label6 = "Savings Name"
GetSystemTimeAdjustment myAdj&, myIncr&, myDisabled&
If myDisabled& then
txtAdjust = "Disabled."
else
txtAdjust = myAdj& & " ns Every " & myIncr& & " ns."
End If
dl& = GetTimeZoneInformation(myTZ)
txtTZBias = CInt(myTZ.Bias / 30) / 2 & " hours"
s$ = myTZ.StandardName
txtTZName = StrConv(s$, vbFromUnicode)
s$ = myTZ.DaylightName
txtTZSName = StrConv(s$, vbFromUnicode)
End Sub
'
' Obtain the system and local time and display them
'
private Sub Timer1_Timer()
Dim myTime as SYSTEMTIME, s$, dl&
GetLocalTime myTime
s$ = string$(255, Chr$(0))
dl& = GetTimeFormat&(LOCALE_SYSTEM_DEFAULT, 0, myTime, 0, s$, 254)
txtLocTime = s$
GetSystemTime myTime
s$ = string$(255, Chr$(0))
dl& = GetTimeFormat&(LOCALE_SYSTEM_DEFAULT, 0, myTime, 0, s$, 254)
txtSysTime = s$
End Sub
John G
VictorC
October 17th, 2001, 09:19 AM
Thanks, I will try it.