VBA Timer

VBA Timer

Anonymous
Not applicable
1,867 Views
8 Replies
Message 1 of 9

VBA Timer

Anonymous
Not applicable
I'm working on a tool (written in VBA) that will position it self at the top
of the screen and drop-down when I bump the edge. This has been a challenge
because I can't figure-out a way to mimic the functionally of the Timer in
VB.

What I'm using right-now is the MouseMove event to drop it down, however it
drops to quickly when I unintentionally graze the edge (with my super-fast
mouse moving ability). What I really want is to bump the edge and begin a
count 1-1000, 2-1000 and drop, but if the user quickly moves the mouse down
prior to the count ending it doesn't drop.

I have searched the web and found nothing that really works; in fact the
solution for a Timer found the VBA help file comes close, but basically
prevents any other processes while the timer function is active.

Has anyone used a timer in a similar application with any success?

Thank you for any help.
Jim Dee
www.caddee.com
0 Likes
1,868 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Have you tried using DoEvents, like:

EndTime = Timer + numSeconds ' Set end time.
Do While Timer < EndTime
DoEvents ' Yield to other processes.
Loop
0 Likes
Message 3 of 9

Anonymous
Not applicable
I basically used the example in the VBA help file as a test, but as soon as
I mouse over the form it pauses for the set time and I can do anything else
for that duration.

Public Sub timertest()
Dim PauseTime, Start, Finish, TotalTime

'If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
' MsgBox "Paused for " & TotalTime & " seconds"
'Else
' End
'End If
End Sub

Thanks,
Jim Dee
www.caddee.com


wrote in message news:5553821@discussion.autodesk.com...
Have you tried using DoEvents, like:

EndTime = Timer + numSeconds ' Set end time.
Do While Timer < EndTime
DoEvents ' Yield to other processes.
Loop
0 Likes
Message 4 of 9

Anonymous
Not applicable
Not saying this will work for you but Sleep API (Google it)is probably your best shot.
0 Likes
Message 5 of 9

Anonymous
Not applicable
I tried that too, because I read a post that suggested that would work. I
hangs until timer ends.

Thanks,
Jim Dee
www.caddee.com


wrote in message news:5554320@discussion.autodesk.com...
Not saying this will work for you but Sleep API (Google it)is probably your
best shot.
0 Likes
Message 6 of 9

arcticad
Advisor
Advisor
This might work.
When you start the timer switch the focus back to AutoCad

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SetActiveWindow Lib "user32" (ByVal hWnd As Long) As Long

[code]

Sub SwitchFocus()
Dim AcadHandle As Long
Dim FormHandle As Long
Dim acadApp As AcadApplication
Dim WindowReturn As Long
Set acadApp = GetObject(, "AutoCAD.Application")
AcadHandle = FindWindow(vbNullString, acadApp.Caption)
WindowReturn = SetActiveWindow(AcadHandle)
End Sub

[/code]
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 7 of 9

Anonymous
Not applicable
I'll give it a try, although I am using a Modeless form, which never has
focus unless the user clicks a control and even then, focus is given back
to AutoCAD immediately following.

Thank you for the suggestion. I'll let you know the result.
Jim Dee
www.caddee.com

wrote in message news:5556371@discussion.autodesk.com...
This might work.
When you start the timer switch the focus back to AutoCad

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As
Long) As Long
Public Declare Function SetActiveWindow Lib "user32" (ByVal hWnd As Long) As
Long

[code]

Sub SwitchFocus()
Dim AcadHandle As Long
Dim FormHandle As Long
Dim acadApp As AcadApplication
Dim WindowReturn As Long
Set acadApp = GetObject(, "AutoCAD.Application")
AcadHandle = FindWindow(vbNullString, acadApp.Caption)
WindowReturn = SetActiveWindow(AcadHandle)
End Sub

[/code]
0 Likes
Message 8 of 9

Anonymous
Not applicable
Jim,

You may want to have a look a the various WaitableTimer Win32 API's. Here is
a link that should get you started:

http://support.microsoft.com/kb/231298

Best Regards,
Wayne
www.plotstream.com
0 Likes
Message 9 of 9

Anonymous
Not applicable
Thanks for the advice, Wayne. I'll give it a shot when I get a chance.

Jim Dee
www.caddee.com

"Wayne" wrote in message news:5558421@discussion.autodesk.com...
Jim,

You may want to have a look a the various WaitableTimer Win32 API's. Here is
a link that should get you started:

http://support.microsoft.com/kb/231298

Best Regards,
Wayne
www.plotstream.com
0 Likes