What operating system are you using?
Main Topics
Browse All TopicsI am having problem with this code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Call Sleep(1000)
error says can't find dll kernel32.
thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Your declaration is correct...something else is wrong. If you put the declaration in a Module then change the Private to Public.
Here is working code with the exact same declaration as you had:
' --------------------------
' Form1
' --------------------------
Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private quit As Boolean
Private Sub Form_Load()
quit = False
Me.Show
Call mainloop
End Sub
Private Sub mainloop()
Dim endTime As Date
endTime = DateAdd("n", 5, Now()) ' 5 minutes from now...
Do While Not quit
If Now < endTime Then
DoEvents ' keep your app responsive
Sleep 50 ' keep CPU cycles down
Else
endTime = DateAdd("n", 5, Now()) ' another 5 minutes from now...
' do something in here...
End If
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
quit = True
End Sub
That is not caused by Sleep()....
Sleep() will cause your program to use absolutely NO CPU cycles.
100% CPU usage results from a tight loop such as this:
Do While True
' do something without calling DoEvents and Sleep()
Wend
The problem you describe isn't related to Sleep()...
Anyway, we are getting off topic.
Seems a bit strange though. I mean, Kernal32.DLL is a pretty big component for windows to be missing. I would think that other programs would be having trouble missing that DLL. Maybe this is a system path issue. Kernal32.DLL is located in your System32 directory. I guess you can make sure it is located there (be sure to have explorer set up to show all files and not hide extensions when you look for stuff in your System32 directory). If it is then maybe copy (that's COPY not MOVE) it over to the directory where your .EXE is running (just to test to see if it finds it in your .EXE directory). If you run the program and Sleep works then maybe you have messed up your windows path or something. Keep in mind that copying Kernal32.DLL over to your working directory is not the solution. It is only a test to see if the Kernal32.DLL file is working. Delete it from your working directory after you tried it out.
If you still get the error then it is likely that either Windows is corrupted or your VB installation is messed up.
At this point, I use some of above codes just flag reset (save it in a table) and close the application for good. The user has to reopen manually.
There are lots of information on this thread, I will go through it at a later time to investigate further. Please forgive me not being able to test it and my possibly unfair pont distribution.
Regards,
Mike
Business Accounts
Answer for Membership
by: vb_elmarPosted on 2005-01-13 at 11:48:42ID: 13037800
I suggest this function:
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Your function was:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)