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




How To Use Sleep Function In VB??


Hi
How to use Sleep Function In VB?? Any help on this?
thanks in advance
Karthik K




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Can I Use Sleep API Function In Thread Function
Hi all

i am trying to use sleep API function within the body of the thread functio, but i can't an error occur

for example

Private Sub Command1_Click()
hThread1 = CreateThread(ByVal 0&, ByVal 0&, AddressOf th1, ByVal 0&, ByVal 0&, hThreadID1)
End Sub

Public Sub th1()
While (True)
Form1.Label1.Caption = Val(Form1.Label1.Caption) + 1
Sleep(1000) ' the error occur when sleep function end
Wend
End Sub

also u must note that when i run the program from the VB its work probably, but when i make an EXE file and run it ... the errors occur

the error messege is:
The instruction at "0x6aaa7339" referenced memory at "0x0000009c". The memory could not be "written".
...

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 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!!!

Sleep Function
Hi,
I am using the Sleep function from win32 lib and my application
freeze.

Obviously because it is used in a loop and I set the time
to 1 millisecond. In the same loop I call DoEvent Function.

The application uses the vbModless in order to show the
window in the taskbar.

The usage of this Mode and the Sleep event is because
the application is using 100% of the CPU

Any help here?

Thank you
Ziko

What Does 'sleep' Function Do?
With reference to my previous thread on copying USB drive



http://www.vbforums.com/showthread.php?t=503894


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


I was told that the 'sleep' function pauses the application for specified time interval. (May not necessarily give time to other processes to run simultaneously ).

Is it true?


So what is the difference between 'sleep' and this loop?


Code:
Dim date1 As Date
date1 = Now
While (DateDiff("s", date1, Now) < 5)
Wend



My main concern is to let my application give some breathing time to other processes while copying folders of several gig in size

Sleep Function In OCX
If i use the sleep function in an OCX will it effect the program that it is using, or will it just make the OCX sleep/

?

ILMV

Sleep Function
Does anyone know how to make a sleep function, I want to make a picture visible, then wait 1/2 a second then make it visible and so on and so on

Thanks

Is There A Sleep Function In Vb?
is there a sleep function in vb? where I can stop my code from running for about 5 seconds to wait for something else to finish.

this is from vb help, I need to wait for my batch file to finish before my code continues. I'm surprised there isn't a wait or sleep function, what am I missing?
Note By default, the Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.

Sleep Function?
is there a way to let the computer wait a little while ( i've got vb 6, learning edition)

in qbasic (yeah, i did a little of that too ) it was just " sleep 1 " or something like that...

Sleep Function
does VB5/6 contain something like a 'sleep' function ? say i attempt to contact a remote server but at the time no connection can be made, and i'd like the code to try again after a wait of 15 minutes

i'm currently sending the errortrap to a timer with an interval of 60000 milliseconds where it loops 15 times, but that seems a rather clumsy way of doing things

Sleep Function ...
Hi Patrick,

Please you can give me an example of a sleep function ?

Thanks in advance
Abilio

Help Using The Sleep Function In VB6
HI All

Wonder if anyone can help. I am using the sleep function, but not sure why I am getting the follwoing error:

Compile Error: Sub or function not defined?

My code is:

Private Sub Form_Load()
Dim Counter As Integer

Call AddToTray(Me.Icon, Me.Caption, Me)

Counter = Counter + 1
Text1.Text = Counter

Sleep 2000

If Counter = 30 Then
Call StockUpdate
Counter = 0
End If

End Sub

Kindest Regards

Peter email@removed

Sleep Function
Hi,

I wanna make my program do nothing for 45 min. because my program should wait for another program to finish and it takes the other program about 45 min to be done.

Should i use CODEPrivate Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Is Sleep Function Bad?
Hey there,
I was doing some reading on the sleep function, and some ppl seem to say it's not a good thing to use. I have a program that will load at the system startup, and i have Sleep set for 300 milliseconds. Is this ok?

Is There A Function Better Than API SLEEP?
I have read that from the internet that API sleep minimum delay is 10ms even though it is "sleep 1".

Is there a function that is almost like the API sleep but much more precise? Real 1millisecond delay?

I have seen some multimedia timer that is able to set the interval to 1ms and it really does. But I really need SLEEP function to do the job.

Thank you.

Sleep Function
When I use the sleep function like this:

WebBrowser1.Navigate "http://www.yahoo.com/index.html"
Sleep (5000)
WebBrowser1.Navigate "http://www.pcmarketfanatics.com/index.cfm"

It throws me an error like this:
"Compile Error: Sub or Function not defined"

Thanks,
Ben

Sleep Function Problem
Hey guys, nice to be here.

Can you please point out why this code doesnt work?

Private Sub Start_Button_Click()

Message_Box.Cls
Message_Box.FontSize = 12
Message_Box.ForeColor = vbBlue
Message_Box.Print "Wait for 10 seconds"
Sleep (10000) ' 10 seconds
Message_Box.Print "10 seconds have passed. Now you can continue"

End Sub

i'm aware that Sleep freezes the whole application but shouldnt it display the first message, then sleep for 10 seconds, and then display the second message? Because as soon as i hit the Start button, the program freezes without displaying the first message.

Any advice on how to make this work?


thanks in advance

Foundas

Get A Function To Sleep, Not Whole Program
First off, sorry if this is in wrong board, I didn't know where to put it. Anyways, I'm writing a program that streams video to a shoutcast server. I have it do it by sending a little bit, sleeping for a tenth of a second, then sending a little more, and it continues this. Doing just this, it works fine.

I'm trying to add other things to my program, which also involve doing things at a certain timing, but the Sleeps are interfering with each other.

I have each part broken into a function. Is there anyway that I can get just the function to pause and allowing other parts of the program to continues as usual? A little searching brought me to SleepEx, but it either is the wrong thing or I'm not using it right, as it does the same thing as Sleep.

TIA

Question About Sleep Function
i tried to use the vb sleep function described here , but i get the following error:
"Member already exists in a object module from which this object module derives"

here is my source:

Code:
Option Explicit
Private Declare Sub sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
Dim User As String, Pass As String, PTries As Integer, UTries As Integer, tmp As String, Tries As Integer
Close #2
Open PList For Input As #2
Line Input #2, tmp
Line Input #2, tmp
Close #1
Open UList For Input As #1
Line Input #1, tmp
Line Input #1, tmp

For UTries = 0 To txtULines - 1
Line Input #1, User
CurrentUser = User
For PTries = 0 To txtPLines - 1
Line Input #2, Pass
CurrentPass = Pass
Inet1.Execute "http://" & Text1, "POST", Text4 & CurrentUser & Text2 & CurrentPass & Text3, "Referer: " & Text5 & vbCrLf & "Content-Type: application/x-www-form-urlencoded" & vbCrLf & "Accept-Language: en-us" & vbCrLf & "Accept-Encoding: gzip, deflate" & vbCrLf & "User-Agent: Mozilla/4.0 (compatiable; MSIE 6.0; Windows NT 5.1; yie6; .NET CLR 1.0.3705)"
lstData.AddItem (User & ":" & Pass)
Tries = Tries + 1
txtTries = Tries
sleep (sleep)
Next PTries
Close #2
Open PList For Input As #2
Line Input #2, tmp
Line Input #2, tmp
Next UTries
End Sub

Private Sub Command2_Click()
Dim UserLines As String, UTitle As String
CommonDialog1.Action = 1
UList = CommonDialog1.FileName
Open UList For Input As #1
Line Input #1, UTitle
Line Input #1, UserLines
txtUTitle = UTitle
txtULines = UserLines
End Sub

Private Sub Command3_Click()
Dim PassLines As String, PTitle As String
CommonDialog2.Action = 1
PList = CommonDialog2.FileName
Open PList For Input As #2
Line Input #2, PTitle
Line Input #2, PassLines
txtPTitle = PTitle
txtPLines = PassLines
End Sub

Private Sub Command4_Click()
Form2.Show
End Sub

Private Sub Form_Load()
On Error GoTo Err_Form_Load
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "All Files (*.*)|*.*"
CommonDialog1.Flags = &H4&
CommonDialog2.InitDir = App.Path
CommonDialog2.Filter = "All Files (*.*)|*.*"
CommonDialog2.Flags = &H4&
Err_Form_Load:
End Sub
thx in advance
-Skeetch

Sleep Function Not Working Too Well
Hello, sleep is causing my system to freeze under the following circumstances
whereas sleep is defined as coming from the kernel32 dll

for i = 0 to 19
sleep 1000
msgbox i & " seconds have passed"
if i = 19 then
msgbox "time is up"
end if
next i

please keep in mind that i do not want to use the timer control for pausing the 1 second - i want to use sleep. any ideas? please respond to my email

jstic04@cp.centennialcollege.ca

Sleep Function In A Module?
Hi everyone,
I'm trying to write a function that uses the "Sleep" command, but when I call the function VB crashes (it stops responding)! My code looks like this:


Code:
Option Explicit

Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Function Test()

Dim a As Integer

For a = 0 To 10
Sleep 1000
MsgBox ""
Next a

End Function


Please help me anyone!

Problem In Using Sleep Function In My Program
hi all,

i had 8 set of pic. one appear after another. initially, my program is as follows:

Delay 1
Picture2.Left = Picture2.Left + f * 1 / 8
Picture3.Visible = False
Picture4.Visible = False
Picture5.Visible = False
Picture6.Visible = False
Picture7.Visible = False
Picture8.Visible = False
Picture9.Visible = False

Delay 1

Picture2.Visible = False
Picture3.Visible = True
Picture3.Left = Picture3.Left + f * 2 / 8


Public Sub Delay(HowLong As Integer)
TempTime = DateAdd("s", HowLong, Now)
While TempTime > Now
DoEvents 'Allows windows to handle other stuff
Wend
End Sub


i find that the delay is too slow and i change it to sleep function and i get the result as attached. what should i do to solve the problem? thanks.

Pause, Wait, Or Sleep Function?
Does anyone know of a function that works in VB for apps (Excel) that provides a simple one-line way to wait for a couple of seconds? The only one I can find is the application.wait method which is awkward because it uses absolute time instead of just like wait 2 seconds.

Can I Use 'sleep' Function By Kernel On Other Processes, And Not My App?
hello,

can I use 'sleep' function by kernel on other processes, and not my app?
so that they will sleep and be on hold?

thanks

Sleep Function Tthat Allows Events ?
I know about sleep , but there is better sleep function i thikn its sleepex, anybody got an example ?

What Is Equivalent Function Of C++ Delay()/sleep() In VB
hi

    in C++ we have two functions sleep and delay. which will stops or waits for some time .

in vb also i want same things , how can i have like this.

thanks
---------------------------------------------
Srinivas.

Threading Fails With Sleep Function In
the module that has the code.

Gurus,
Here is the situation, I have the following code in module. I have a form that has a button. On clicking this button, i create a thread using createthread() api to execute the thread. when I am in IDE/Debug mode, the program does not give an error. But when I make it an exe and run the exe, the program aborts with "The instruction at 'xxxxxxxxxxxxxx' referenced memory at '0x0000009c'. the memory could not be 'written'.

But when I comment the sleep statement , the make an exe and run the exe, it works fine.

Is there anyway to solve this issue.

Thanks, I appreciate your help

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

and try to multi-thread the following function, I get an access violation.

Public Function addtext()

i = 0
'Do

While i = 0
Sleep (1)
If i > 0 Then
Form1.Text1.SelText = "i > 0 "
End If
Form1.Text1.SelText = "adding to textbox "
Wend
'Loop

End Function
</b>

Making A Function Take Longer To Execute (sleep ?? ))
Hi
I need to make a function take longer to execute, but not by inserting loops and so, perhaps a function that delays the execution of instructions.
I need this because I need to use an object with php and php unloads the object just after the function returns anything.
Or perhaps I could return the value of a function from an other (very unlikely to me)?
Thanks!

Lookin For A Sleep Function Or Some Type Of Delay Which Doesn&#039;t Use System Resources.
Hey there guru's is anyone aware of a sleep/delay function that will not use system resources like a timer will.


Thank ya all in advance.

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.

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