I need some help using Visual basic 6.0 to read the computer's clock and use it to execute a command at a specific time of day. I am using the computers parallel port and visual basic to control a stepper motor and I need the motor to turn on at specific times of day. The program will run all the time and say for example 3 o'clock hits, visual basic will execute a command and turn on the motor. I am having some trouble finding information for this, as I am a pretty novice visual basic user. Anyone have any information and/or links for me? Thanks!

Sure,

The function is simply "Time", but it comes in a specific format. You can use the format function, to specify the format the time returns for example:

dim CTime as string
CTime = format(time, "h:mm:ss")
if CTime = "22:25:00" then
   msgbox "it's 10:25pm"
end if

If you research the format and time function, you can have it set for 24 hour time, or 12 hour time, and you can specify how many digits per part of the time. Then just compare and execute :) Keep in mind, however, that you would want to put this in a timer control, and set the interval to either 1 second or 100Milliseconds (I use 100ms, but every second would work just as well), the timer control's interval property works in Milliseconds, so 1 second would be 1000ms. Also, remember to disable the timer, or set a flag variable after the time hits, and the program runs the commands, otherwise, it will continue to run those commands over and over again until the time is no longer (in this case) 22:25:00. Let me know how it turns out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.