A pause in Visual Basic?

Electronics Computer Programming Q&A
Post Reply
chapter30
Posts: 59
Joined: Mon Jan 24, 2005 1:01 am
Location: Detroit, MI
Contact:

A pause in Visual Basic?

Post by chapter30 » Mon Jan 24, 2005 6:07 pm

Does anyone know how to have a Visual Basic program pause for about a second? I am communicating with a pic project and the VB software is sending the data too fast for the hardware to keep up.<p>I've been using the computers clock by using code that looks like this:<p>vtime = Second(Time) 'store the clocks second
vatime = vtime + 2 'this variable is to compare<p>
Do Until Second(Time) > vatime

Loop
GoTo info1
End If<p>This is causing problems if the second is on 58 or 59 when the variable is loaded. I could add more code to prevent this but I would rather use something more tidy.<p>Due to program size restrictions in the PIC I would rather not use any type of acknowledge from the hardware.<p>Thanks for the help.<p>-Jeff

User avatar
CeaSaR
Posts: 1759
Joined: Sat Nov 08, 2003 1:01 am
Location: Phoenixville, PA USA
Contact:

Re: A pause in Visual Basic?

Post by CeaSaR » Mon Jan 24, 2005 6:22 pm

Look in VB's HELP file for TIMER. You should be able to find the necessary information there.<p>Of course you could use something like this (from QB4.5):<p>'code here
T1$ = TIME$
T2 = 0
DO UNTIL T2 = 5
seconds1 = VAL(RIGHT$(T1$, 1))
seconds2 = VAL(RIGHT$(TIME$, 1))
IF seconds2 < seconds1 THEN seconds2 = seconds2 + 10
T2 = seconds2 - seconds1
LOOP
'more code here<p>This will give you a 5 second interval. Just play with the variables to get the desired time out you need.<p>CeaSaR<p>[ January 24, 2005: Message edited by: CeaSaR. ]</p>
Hey, what do I know?

hp
Posts: 245
Joined: Sat Aug 09, 2003 1:01 am
Location: Friendswood, TX
Contact:

Re: A pause in Visual Basic?

Post by hp » Mon Jan 24, 2005 7:39 pm

Delaying a program is very simple.<p>Add the following in a module or at the top of your form code:<p>Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)<p>Then call Sleep <milliseconds> everytime you want to delay the program.<p>Example: Sleep 1000 '1 sec delay<p>Harrison

chapter30
Posts: 59
Joined: Mon Jan 24, 2005 1:01 am
Location: Detroit, MI
Contact:

Re: A pause in Visual Basic?

Post by chapter30 » Tue Jan 25, 2005 2:34 am

Both of these work great and have taught me a lot about this program. I'm going to have to pick up a book on the subject.<p>Thanks a lot.<p>-Jeff

User avatar
CeaSaR
Posts: 1759
Joined: Sat Nov 08, 2003 1:01 am
Location: Phoenixville, PA USA
Contact:

Re: A pause in Visual Basic?

Post by CeaSaR » Tue Jan 25, 2005 7:01 am

I use sleep when it doesn't matter if a keypress or other event stops the sleep timer. If I want a forced time delay, I'll use either method I described in my previous post. Just my preference. Use whatever method works best for your situation.<p>CeaSaR
Hey, what do I know?

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests