• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1285
  • Last Modified:

Sleep function for visual basic ActiveX apps


I would like to know how to perform a sleep in an Visual Basic ActiveX application. We have tried the following so far.

1) Creating an Alt/com object in MFC to be used by the Visual Basic ActiveX app. This seems to fail after a few calls. Maybe there is a conflict within the ActiveX apps even though each one is supposed to have their own Alt/Com

2) Tried a multithreaded C DLL with a sleep function call.
Had the same problem as choice 1.

Is there a vbasic sleep for ActiveX apps ?

Thank You.
1 Solution

                 Copy this code into the declarations section of the project.

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


                 To delay the program for 1 second, use this code:

                 Call Sleep(1000)    
kkandasaAuthor Commented:
Tried it. Still does not work. Some of the apps error out at the
sleep line. When this happens, the On error goto label of the current function is not executed.
Instead On error goto label of a calling higher level function
is executed.
Appreciate any help/suggestions.
Off the top of my head, so it may contain syntax errors:

Place a timer control (Timer1) somewhere on your form. Add the following subs:

Sub Sleep(iDelayMS as integer)
  ' Program the timer and start it.
  Timer1.Interval = iDelayMS
  Timer1.Enabled = True

  ' disable user interaction
  Form1.Enabled = False

  ' Timer1 becomes disabled after it has expired:
  While Timer1.Enabled

  ' enable user interaction
  Form1.Enabled = True
End Sub

Sub Timer1_Timer
  'disable timer when it has expired.
  Timer1.Enabled = False
End Sub

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

what version of vb do you have?

kkandasaAuthor Commented:
We are looking for something to do in code i.e wait in a ActiveX
application which has no forms.  We cannot use a timer control.
kkandasaAuthor Commented:
Version 5.00
the Sleep() function staticsnow told you is suppose to be working... Please tell me do you need the function for the C DLL or for VB code.....??? Thanks....

declare sub Delay( N as Long )
Dim S as Long
  S = GetTickCount + N;
  While GetTickCount < S do Yield;
end sub

YOu need to declare the following functions in the declaration section of your unit...

GetTickCount()   Yield                  

Example call : Call Delay(100)    ro Delay(100) or
dim a as long

a = Delay(100) or you think of it....don't know how to work in VB that good...

I don't know if the syntax of this is rightm, but I have the code for Delphi so tried to convert it to VB even though I don't know how to work very much in VB...

Viktor Ivanov
You can do it without showing forms. You can access the form without it being visible.
 Sleep should work. It does in my case.
Sub Wait(sngDelay as single)

     dim sngFinish
     'sngFinish is the timer value that will be true even
     'Near midnight

     sngFinish = (timer+sngDelay) mod 86400

     loop while timer < sngFinish

end sub

This Works For Me
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now