Delay Loop Or Sleep
I am using VB2005, I would like to insert a time delay process, say 5 mins, between reading data from several instruments. However I also would like to include a STOP button, when it is clicked, the delay process would be killed as well.
How can I write such delay function? Thanks!
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Creating Delay With Sleep... In A Loop Causes Program To Freeze For A While
Hello, thanks for the advice to use Sleep function instead of DoEvents() in order to create a delay, this did not cause a 99-100% CPU usage.
But anyway, some problems ahead. I need to have this sleep function in a For loop, which causes the program to go into a "not responding" state for a while until recovery..
I would need the sleep function to be called in a loop like this
For x = 0 to 15
'here I open com port send values and close com port
well as i said before this freezes the program for a while. stopping the for loop on the middle with msgbox for instance the loop with the sleep function works as it should
im trying to make a program that outputs a series of numbers. i want to output 1, 2, 4, 8. i want to create a delay before it will output the next number. pls give me a sample program of that.
tnx a lot
Sleep() Or Delay Equivalent In VB
Is there a function that is equivalent to C++ sleep() or delay() in vb?
I have seen many examples for timers and i cant make heads and tails of them.
I am new so the vb code lingo is hard for me to understand.
Can someone please tell me how i can pause a function for a small interval of time and explain the code in detail if possible.
PS also, i set the border style to none but now i cant move the ap at all. any ideas on how to move the ap with the mouse left click event without the border?
Mud Delay/Sleep/pausing Please Help
I have a problem with a textbase game I am using which is in VB6. The problem is I want to slow down the player's movements. I cant figure out the code to slow a specific player down. I know the sleep command puts the program on pause, but that is not good if there is more then one person playing. I need the program to run. here is an example of the probelm.
I type west and I instantly move to the western location. I want to take about 3 seconds before I actually move. I don't want to freeze the program but freeze the player only. The reason I want to freeze the player and not the program is once again if there is 20 people playing and moving around, I don't want everyone to experience lag even when they are not moving...
Well ive looked quite alot of times for this, ive found a heep of Sleep functions and they all just dont do what i need them to do. I want
Text1.Text = "1"
Text2.Text = "2"
Text3.Text = "3"
Etc, but when all the other sleep commands ive used, they all just sleep for the ammount of time right at the start, and then print out all of the text.
I need something that sleeps, then reads the next line etc. Thank you (and i dont want to use timers)
I have a function that runs in a loop and the functions sends information to a control, then the control sends back information. I would like to give the control time to send back information before I run the function again the loop. Can I someone wait a second before running the function again?
Do While/until Loop + No Sleep For 3 Days
can somebody help me with this do while loop... i run the program and it's supposed to keep playing the game 10 times but when i put a number in it goes straight to the ending msgbox. i know this is probably easy but for some reason i'm not seeing it. we haven't covered the do while/until loops in the class yet but it makes more sense to use it here, unless anybody has any other suggestions. there's probably a lot of errors in this program right now but i'm in the process of fixin them (well trying to)
Public Attempt_Count As Integer
Public Win_count As Integer
Public Loss_count As Integer
Private Sub cmdGuess_Click()
Dim guess As Long
Dim i As Long
If IsNumeric(txtGuess.Text) Then
guess = CInt(txtGuess.Text)
Select Case True
If (guess > 0) And (guess < 101) Then
i = Int(Rnd() * 99) + 1
MsgBox ("Value out of range")
If (guess > 0) And (guess < 1001) Then
i = Int(Rnd() * 999) + 1
MsgBox ("Value out of range")
If (guess > 0) And (guess < 10001) Then
i = Int(Rnd() * 9999) + 1
MsgBox ("Value out of range")
MsgBox ("Must enter a numeric value")
If guess = i Then
lblResult.Caption = "YOU GUESSED THE NUMBER!"
Win_count = Win_count + 1
ElseIf guess < i Then
lblResult.Caption = "The number is higher"
Loss_count = Loss_count + 1
lblResult.Caption = "The number is lower"
Loss_count = Loss_count + 1
Attempt_Count = Attempt_Count + 1
Loop Until Attempt_Count = 10
If (Attempt_Count = 10) Then
If MsgBox("Game Over" & vbCrLf & vbCrLf _
& "Wins: " & Win_count & vbCrLf & "Losses: " & Loss_count & vbCrLf & vbCrLf _
& "Would you like to play again?", vbQuestion + vbYesNo) = vbNo Then
Loss_count = 0
Win_count = 0
Attempt_Count = 0
txtGuess.Text = ""
lblResult.Caption = ""
Interupt Sleep Loop- Possible? *Resolved
With the following code
While Time < "8:01:00 PM" Sleep 30000 'wait 30 secondsWend
only problem is once it's in this loop. the user can't interupt/pause/cancel the program without crashing and restarting the task.
Is there anyway to insert into the While loop
If User wants to cancel Then exit sub End If
possibly through combination of user clicking a cancel button on form, or Mouse_down event, or key_down.
How To Add Delay In Loop.
I am setting up a progress bar to loop when a toggle button is clicked, so that every time the progrss bar value = 100, i can do some things.
My problem is, that when i set the loop going with the toggle button, the loop works, and it wont let me un-toggle the button. How can i add a 10sec delay at the end of the loop, so that the progress bar only loops every 10 sec's. Then i can un toggle the button if I want to.
Thanks For the help.
Hi, not sure if this is the right section, so apologises if it's wrong.
I'm coding in Visual Basic in Microsoft Access 2003, trying to make a simple program for a School project.
Basically, I have written a loop so on the click of a button the number in a text box goes from 0 to 100, the only problem is it moves so fast you can't see it and just jumps from 0 to 100 without the numbers inbetween coming up. Is it possible to add a delay or pause to slow down the transition ?
hey, im quite new to visual basic so i dont know much. i was wondering how do i make a delay loop, for example like a countdown, like i click a button and it displays 1 to 10, one second a number( like 10, then it waits a seccond, 9, waits another second and so on) and when it reaches 0 more text appears or a new form opens up and stuff like that.
can i write a loop which loops every second (or whatever)
loop 'every 5 seconds
How To Delay The Counter In Loop
how to delay the counter in the loop.???
while i < 1000
//here should have some keyword to set the counter delay for i second..//
i = i + 1
Delay Between Each Time To Run The Stuff In A Loop
I'm kinda noob, so there is probably a easy way to do this, but cant find it.
I've got a program going on that is supposed to browse a link all the time with a loop
Private Sub cmdLoop_Click()
so, it doesn't work cause i want the page to load for about a half second before it's time to do the command again, like some kind of delay between every time to do the loop.
Sleep Little Thread, Sleep
Hi out there.
I'm getting stupid! I created a new thread. The thread calls a function which sets a textbox on a form to current time. Works well but my cpu is running 100%. No question cause there is a do ... loop with text1 = time$ inside. Going forward i inserted a sleep(500) into the loop. Guess what happened? The app crashed. Now tell my why. I tried everything. Any ideas?
Public Function threadDO()
Form1.text1 = time$
Help With Sleep
i wanted to "deal" one card at a time (load pictures) by using the sleep function in between but when i do that it doesnt go smoothly because by the time the 1 picture loads it is already "sleeping" so it looks like it froze
is there any other "pause" or wait comand that i can use that just takes up time in the program instead of freezing it?
Sleep Not Available In VB 6.0 ?
I like to run trough a while loop every second util the wile exists.
So i need to sleep my program a second in the loop.
But Sleep(1000) doesn't work
How can i do that?
While Not (Dir$("C:Program Fileslijst.pdf") <> "")
MsgBox ("Nog niets gevonden")
What are the API's to be called for the SLEEP command??
Sorry, I found it.
Declare Sub Sleep Lib "kernel32" Alias "Sleep" _
(ByVal dwMilliseconds As Long)
Mods delete this thread or let it die.
I am looking for a way to make a Vbprogram pause for a certain number of milliseconds. e.g.
Sleep (500 millisecs)
Whats the easiest way to do this....
if i do:
The program freezes.
Why will my code not sleep???
strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "Admin2")
strComputer = "."
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/Admin2,user")
Originally posted by Ad1
check out the SetSystemPowerState API, if you don't already have it then I recommend you download the API Guide
Ad1, do you know if Windows 2000 is the only version of NT that supports power-saving features? The compatibility for the API is "Requires Windows 2000 or later; Requires Windows 95 or later", and I was wondering if I would need to use a different API if power-saving features are supported on NT 4
is there any simple code that will put the computer into sleep mode??
How can i make my program sleep for a few seconds. I would like to let my splash-screen appear for more one 1 ms.
No Sleep !
I am in a middle of a loop and need to pause the application for 10 sexonds.
Unfortunately, using the Sleep() will hang my application for 10 seconds
Is there any better idea than Sleep ?!
Help With SLEEP
First of all, I am using VB6 on an NT platform. I wrote a simple VB6 routine to run an FTP job every 12 hours, transferring a text file from an old unix server to my pc. I have been able to run the FTP successfully in other programs and it works perfectly when I add the SLEEP. Every 12 hours, the routine runs, yet when this program is SLEEPing in the background it interferes with the logon process of a unix inventory tool. As soon as I shut down my VB program, the unix tool allows me to logon. So, each operates perfectly independant of one another, but the VB routine somehow is causing a problem.
I can, however, logon to the unix tool first, then run my VB FTP routine and both work fine, but if I start up my VB FTP program first, the unix tool won't let me logon.
Here is how my SLEEP is declared:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Here is how my SLEEP is used:
Has anyone else had a problem like this, and is there a fix? Any guesses at to what the problem is? Is there a replacement I can use in place of SLEEP? Any help would be appreciated.
P.S. By using my "Task Manager", I can tell that my VB6 program is NOT causing excessive memory or processor usage (nor is the Unix tool), so that can't be the problem.
Is there like a sleep/pause function in vb ?
I am trying to use sleep, but it does not seem to work (sub or function not defined). Are there any alternatives?
I am looking for something like the sleep() command in other languages. Want my code to pause for a set(-able) time, without having to rebuild my whole application to use the timer-object.
Thanks for your help!!!
If found a code using this
Declare Function GetTickCount Lib "kernel32" () As Long 'PausePublic Sub Pause(HowLong As Long) Dim u%, tick As Long tick = GetTickCount() Do u% = DoEvents Loop Until tick + HowLong < GetTickCountEnd Sub
so what is the different between this and Sleep ?
which 1 is better..?
Here is my code, I am running on Windows NT.
Private Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Command1_Click() Sleep 100MsgBox "Done" End Sub
However, it crashes at the sleep command. Is there any reason why this isn't working?? It works through Perl without any problems.
I have this other program, and I wanna freeze it for a period of time. How do I do this?
What's the syntax for using the Sleep function in VB?
I know this is on here somewhere already, but since Search has been disabled I thought I'd ask again.
Is there a code that will stop my code from executing for a couple seconds?
Like a Sleep function?
Maybe I Need To Get Some Sleep But..
why do I keep getting a zero here ( rEs ), no matter what ?!!
Dim rEs As Long
Dim fOp As SHFILEOPSTRUCT
.hWnd = hWnd
.wFunc = FO_DELETE
.pFrom = KlisT
.fFlags = FOF_FILESONLY Or FOF_ALLOWUNDO
rEs = SHFileOperation(fOp)
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
why does this cause a compile error when I have it in the declarations of my forms code. And if it's not supposed to go there, where does it go?
Is there like a Sleep function, that waits how many seconds you tell it to, and then continues on with the code?
I know in QBasic you typed "Sleep 2" and it would wait 2 seconds, but no such luck with VB
In QBasic I recall a command to 'sleep' for a certain period of time. I have not programmed for a LONG time and I now need a little application to execute a file, then 'sleep' and execute it again with another variable (ie. file.exe 123, then 5 seconds later file.exe 111 etc.)
Being that I do not have a copy of VB or QB on this computer, does anyone know if something like this is possible with a batch (.bat) file? If it is not, does anyone know if it is possible in PHP (the PHP script actually calls the executable, so in essence I wouldnt need a batch file if the PHP could do the same thing...)?
If niether is an option, I guess I'll just get a copy of Basic and complie it as an exec.
plz can some one send me sleep code with declaration
and if it use module form tel me how
i try all way it't work
and i was 2 use this decration
Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
How can I "sleep" for a while in my program.
I don't want to do busy waiting.
Is There Sleep() ?
Is there a command for a timedelay (in milliseconds) in VB? Something like delay() or sleep()? I tried faking it with a loop while a timer makes some variable True, but the program just hangs. Thanx.
Is there any command similar to VC's Sleep(int) command? Thanks for any advice!
How To Use Sleep In VB
I have looked in MSDN but come away still wondering how to use the Sleep function with VB. Can anyone show an example?? Or is there a compatible function in VB that is easier to use?
Do/Loop,Need To Nest Another Loop To Check For Duplicates(FIGURED IT OUT)
check it out, what i am doing is reading in from my DB, customer orderID's. The table that i am reading from will have multiple OrderID's and some will be duplicates. That all fine but i dont want to have order number 115 show up 3 times when 1 time would be enough. This is the loop that i am using and am loading the values in the the combo box. What i would like to do, is once i hit this line of code
Combo2.List(i) = ![OrderID]
then do either a for each , or for next loop to walk through the contents of combo2 and check for a duplicate, if a duplicate is found i would like to take the current orderID that was just loaded out of the combo2 box. I have tried a for each loop but i am not geting the syntax correct of what exactly i am trying to search through. That where you guys come into play. could some one please help with this problem
Do Until .EOF
Combo2.List(i) = ![OrderID]
i = i + 1
This is what i would like to accomplish.
DO Until .EOF
load orderID into combo box
For Each orderID in combo box
If duplicate found then
delete current entry
continue loading orderid's
Edited by - lmf232s on 7/24/2003 1:59:30 PM
About The Sleep Function
Hi, I don't know how to work the sleep function, is it something I have to define, or is it an API, I'm lost, if someone could please help, thanks
Sleep API Call
I wanted to use the API call sleep, the declaration of it is below:
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
I read about it on AllAPI.net. It says "A value of INFINITE causes an infinite delay." for the parameter "dwMilliseconds".
Firstly how can I pass an infinite value to it & secondly is there anyway that I could cancel the infinite delay after i passed an infinite value to it.
Thanks in advance
App Sleep In Some Seconds?
how can i make my application sleep (not working) in some seconds before do something else .