Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Loop Sleep


Hello,

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?

Thanks!@#$




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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)


Code:
Option Explicit

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

Do
If IsNumeric(txtGuess.Text) Then
guess = CInt(txtGuess.Text)

Select Case True
Case optRange(0)
If (guess > 0) And (guess < 101) Then
Randomize
i = Int(Rnd() * 99) + 1
Else
MsgBox ("Value out of range")
Exit Sub
End If
Case optRange(1)
If (guess > 0) And (guess < 1001) Then
Randomize
i = Int(Rnd() * 999) + 1
Else
MsgBox ("Value out of range")
Exit Sub
End If
Case optRange(2)
If (guess > 0) And (guess < 10001) Then
Randomize
i = Int(Rnd() * 9999) + 1
Else
MsgBox ("Value out of range")
Exit Sub
End If
End Select
Else
MsgBox ("Must enter a numeric value")
Exit Sub
End If

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
Else
lblResult.Caption = "The number is lower"
Loss_count = Loss_count + 1
End If

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
Unload Me
Else
Loss_count = 0
Win_count = 0
Attempt_Count = 0
txtGuess.Text = ""
lblResult.Caption = ""
Exit Sub
End If
End If
End Sub

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!

Interupt Sleep Loop- Possible? *Resolved
With the following code

VB 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


VB Code:
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.

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

Sub SendingValues()

For x = 0 to 15

'here I open com port send values and close com port

Sleep 1000

Next

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

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()
Do
Sleep 500
Form1.text1 = time$
Loop
End Function

Yours

buzz

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") <> "")
Sleep (1000)
MsgBox ("Nog niets gevonden")
Wend

Sleep API
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.

Sleep?
hi all,

I am looking for a way to make a Vbprogram pause for a certain number of milliseconds. e.g.

While (condition)
Sleep (500 millisecs)
[statements]
Wend

Whats the easiest way to do this....

if i do:

While(condition)
Wend

The program freezes.

Sleep
Why will my code not sleep???


Code:
strComputer = "."
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "test"
objUser.SetInfo
sleep 3000
strComputer = "."
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/Admin2,user")
objGroup.Add(objUser.ADsPath)

Sleep
Quote:




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

Sleep
is there any simple code that will put the computer into sleep mode??

Sleep
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 ?!
Thanks.

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:
Call Sleep(43200000)

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.

Thanks,

VisualBasicUser

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.

Sleep
Is there like a sleep/pause function in vb ?

Thank You,

Sleep
I am trying to use sleep, but it does not seem to work (sub or function not defined). Are there any alternatives?

sleep 100

Sleep()?
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!!!

Borniet

Sleep
If found a code using this


VB Code:
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


to pause,

so what is the different between this and Sleep ?

which 1 is better..?

Cant Sleep!
Hi All,

Here is my code, I am running on Windows NT.



VB Code:
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.

Cheers!

Paul.

Is Everyone Gone To Sleep?
Where is all the experts?

Sleep API?
I have this other program, and I wanna freeze it for a period of time. How do I do this?

Sleep
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.

Sleep
Is there a code that will stop my code from executing for a couple seconds?

Like a Sleep function?

Thanks

Maybe I Need To Get Some Sleep But..
why do I keep getting a zero here ( rEs ), no matter what ?!!


Code:
Dim rEs As Long
Dim fOp As SHFILEOPSTRUCT

With fOp
.hWnd = hWnd
.wFunc = FO_DELETE
.pFrom = KlisT
.fFlags = FOF_FILESONLY Or FOF_ALLOWUNDO
End With

rEs = SHFileOperation(fOp)
Debug.Print rEs

Sleep
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?

Cheers
Nick

Sleep?
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

Thanks.

Sleep
Hi,
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.

Thanks,
Larry

Sleep
plz can some one send me sleep code with declaration
and if it use module form tel me how
thx
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)


kazanova

Sleep
Hi,

How can I "sleep" for a while in my program.
I don't want to do busy waiting.

Thanks.

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.

Sleep
Is there any command similar to VC's Sleep(int) command? Thanks for any advice!

How To Use Sleep In VB
Hello,
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?

Thanks,
Sean

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
   .MoveNext
Loop

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
             end if
         next
     continue loading orderid's
loop



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
Hi,

I wanted to use the API call sleep, the declaration of it is below:

Code:
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?
hi all,
how can i make my application sleep (not working) in some seconds before do something else .
thanx.

Try To Use Timer Instead Of Sleep.....
My program used to have many sleep statements and the application will freeze then. Now I am using another delay function:
Public Sub Delay(lngSeconds As Long)
Dim lngStart As Long
lngStart = Timer

Do While Timer <= lngStart + lngSeconds
DoEvents
Loop
End Sub
But suppose I want to stop the application in the middle, I need to click stop button or just close the application. The problem is even I close the application, the process is still going. Anyway to make it really stop right there and quit whatever function the process is in?

thanks.

Question To SLEEP
Does SLEEP stop all activity of the computer for the choosen time?
Means - all multi-tasking-processes (if there are any) are stopped, too?

Sleep And SendKeys
I'm trying to use Sleep to delay between SendKeys and it's acting strange. I put code similar to the following:

AppActivate "HP Precisionscan Pro"
Sleep 500
SendKeys "[A bunch of keys]"
Sleep 500
SendKeys "[A bunch of keys]"

The program pauses after it activates the app but then it sends the keys from both SendKeys statements without pausing at all. Am I using the Sleep function wrong?

Sleep API Problem
Hi again, when I use the sleep API, where do I paste this line

Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

into my code?

I've tried a number of different places, but I always get the same error:

Complie Error
Only comments may appear after End Sub, End Function or End Property

Please tell me what I'm doing wrong, thanks.

jonny

Sleep Function?
Is there a sleep function (or timer) in VB? Our program is working too fast!

Thanks!

Sleep Function
Hey dear kind people reading this...

HELP!!!
I want to have a delay in my program
But it won't work with a timer
So, I know I need to use the sleep function
But I don't know how
Could someone please help with the code, and explain what's going on if possible
Thanks so much!!!

Is There A Better Way I Could Write This(using Sleep)
the problem im having now is that i get vb to look into a pages source stored in txtSource then return what im looking for. but as the web page takes a couple of seconds to load my code has all ready cycled through so i dont get a value returned. I thought about using the sleep process to help. here is what iv got


Code:
Private Sub btnGet_Click()
On Error Resume Next

'Enable timers
Timer1.Enabled = True
Timer2.Enabled = True

Dim UserName
UserName = "http://www.squatjuice.com/cgi-bin/yabb/YaBB.pl?action=viewprofile;username=" & cboAddress.Text
If cboAddress = "" Then Exit Sub
WebBrowser1.Navigate UserName

Sleep (3000) 'Delays for 3 seconds

'contine you process

UserAvailable = IsUserOnline(txtSource)
If UserAvailable = online Then
MsgBox ("User Online")
End If
If UserAvailable = Offline Then
MsgBox ("User Offline")
End If
End Sub
the problem that im having is that the whole proces is paused for 3seconds. what i was hoping for is that it would run the first pice of code then sleep for 3seconds then continue. any suggestions???? i hope i explained this ok

DoEvents Or Sleep (API), Which Is Better?
just wanna know ur opinions/understanding regarding the two stuffs, DoEvents and Sleep(API).

which one is better? and for what application do i use each?

i have been using these two separately and i could see that SLEEP pumps CPU Usage lesser than DoEvents.

any opinions are welcome

Sleep And Events
Does the sleep API calls allows processing of events during the sleeping interval?

Sleep Problem
I'm using the sleep api in my program

--> Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

and whenever I use a sleep value of over about 50 it locks the program up and also the rest of my computer, but if I do a smaller value it works fine, problem is I want to sleep for 1000. I'm using it along with sendkeys so maybe thats whats causing it?

code looks like this:

sleep 1000
sendkeys "{ENTER}"
sleep 1000
sendkeys "{ENTER}"
sleep 1000
sendkeys "{ENTER}"
...
and so on, hitting enter about 20 times
I also tried it as a loop and it locks up that way too.
What the heck is going on, it should just pause the program not my whole system right? Help please!

Need Help With The Sleep Command
Hey, I've tried to use the sleep API to suspend my program for certain amount of time, but even though the sleep (number) is inside a button sub, it begins counting when the form loads, what am I doing wrong?


Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

[i]unrelated code here[/i]

Private Sub cmdEnter_Click()

Call GoToStep1
Sleep 8000
Call Step2

End Sub

Sleep Method In .Net
I tried to Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
but I got error. I 'm using .Net not VB 6.0
I want to pause my application for some secs.. Usually I used Sleep but Sleep is unknown in .Net. I couldn't find which header file to import. Please help me

Copyright © 2005-08 www.BigResource.com, All rights reserved