Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My first GetLocalTime

Status
Not open for further replies.

UncleCake

Technical User
Feb 4, 2002
355
0
0
US
I am trying to do my first API call in VB. I am trying to do the GetLocalTime. I think that I have the module set up correctly, but I don't know how to call it. Below is my code, can any own help. It is telling me that the systemtime variable is not defined in MsgBox (GetLocalTime(systemtime)).

-Uncle Cake

MODULE:

Option Explicit


Public Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As systemtime)
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

FORM:

Private Sub Command1_Click()
MsgBox (GetLocalTime(systemtime))
End Sub
 
I am a C++ programmer and not familiar with VB, but what I can read of it I suppose you have a type systemtime, but you need a variable of the systemtime type.

Marcel
 
Marcel,

My problem is that I don't know what I am doing and I am trying to learn so I am lost. I am going to keep working on it.

-Uncle Cake
 
In that case I suggest you take a look at one or more tutorials for VB. I suppose many are available on the web, I think at some of the partner sites of this site they are available. You could also buy a book.

Marcel
 
Actually your problem is this. Some of the Windows API's return a value (string or long) others return a type.

What your actually doing is creating a type called systemtime, and passing that to the API. The API will fill in the values for the type and return it to you. This is almost like an array, but non re dimmable. I've changed your code to help get you started.
[tt]
Option Explicit

Public Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SystemTime)
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 Sub Command1_Click()
' You need to have a variable of
' the SystemTime type

Dim varSystemTime as SystemTime
Dim strMessage as String

GetLocalTime (varSystemTime)
strMessage = " Year : " & varSystemTime.wYear & _
vbCRLF & " Month: " & varSystemTime.wMonth & _
vbCRLF & " Day of Week: " & varSystemTime.wDayOfWeek& _
vbCRLF & " Day: " & varSystemTime.wDay & _
vbCRLF & " Hour: " & varSystemTime.wHour & _
vbCRLF & " Minute: " & varSystemTime.wMinute & _
vbCRLF & " Second: " & varSystemTime.wSecond & _
vbCRLF & "Milli Second: " & varSystemTime.wMilliseconds
MsgBox strMessage

End Sub[/tt] Craig, mailto:sander@cogeco.ca

"Procrastination is the art of keeping up with yesterday."

I hope my post was helpful!!!
 
Uncle did this help? Craig, mailto:sander@cogeco.ca

"Procrastination is the art of keeping up with yesterday."

I hope my post was helpful!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top