×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

My first GetLocalTime

My first GetLocalTime

My first GetLocalTime

(OP)
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

RE: My first GetLocalTime

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

RE: My first GetLocalTime

(OP)
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

RE: My first GetLocalTime

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

RE: My first GetLocalTime

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.

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

Craig, mailto:sander@cogeco.ca

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

I hope my post was helpful!!!

RE: My first GetLocalTime

Uncle did this help?

Craig, mailto:sander@cogeco.ca

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

I hope my post was helpful!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close