Solved

Sleep function for visual basic ActiveX apps

Posted on 1998-10-05
9
1,218 Views
Last Modified: 2013-11-25
Hello,

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

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.
0
Comment
Question by:kkandasa
9 Comments
 

Expert Comment

by:staticsnow
ID: 1438321
Declarations

                 Copy this code into the declarations section of the project.

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

                 Use

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

                 Call Sleep(1000)    
0
 

Author Comment

by:kkandasa
ID: 1438322
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.
0
 
LVL 12

Expert Comment

by:fulscher
ID: 1438323
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
    DoEvents
  Wend

  ' enable user interaction
  Form1.Enabled = True
End Sub

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

 
0
 

Expert Comment

by:staticsnow
ID: 1438324
what version of vb do you have?

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:kkandasa
ID: 1438325
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.
0
 

Author Comment

by:kkandasa
ID: 1438326
Version 5.00
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1438327
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...

Regards,
Viktor Ivanov
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1438328
You can do it without showing forms. You can access the form without it being visible.
BTW
 Sleep should work. It does in my case.
0
 

Accepted Solution

by:
Fantym earned 100 total points
ID: 1438329
Sub Wait(sngDelay as single)

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

     sngFinish = (timer+sngDelay) mod 86400

     Do
          DoEvents
     loop while timer < sngFinish

end sub

This Works For Me
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now