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

Timer Problem

I am trying to create a program using VB5 that controls another Windows application. This program first launches the application then initiates a login to an internet FTP site.  I make the program wait for the "Login Welcome Message" then pause 10 seconds to let my files list.  At this point I send keystrokes to download the first file in the list.  Now I want the program to wait 15 seconds to allow the files to download before the program exits.  My problem is, the first pause statement seems to work just fine but the program totaly ignores the second pause statement and jumps to the keystrokes that exit the program before my files have had a chance to download.
Please see code below:

Line1:
  nRet = AppActivatePartial(Trim("Login Welcome Message"))
    If nRet Then
      Title = Space$(256)
      nRet = GetWindowText(nRet, Title, Len(Title))
      If nRet Then
        PauseTime = 10
        Start = Timer
          Do While Timer < Start + PauseTime
          Loop
      AppActivate "Login Welcome Message"
      GoTo Line2:
      End If
    Else
GoTo Line1:
Line2:
SendKeys "~"
SendKeys "{DOWN}"
SendKeys "%{C}"
SendKeys "{W}"
PauseTime = 15
  Start = Timer
    Do While Timer < Start + PauseTime
    Loop
SendKeys "%{F}, {X}"
End If
End Sub



Any help would be greatly appreciated.

Thanks,

Don
0
deross
Asked:
deross
  • 6
  • 4
  • 3
1 Solution
 
Erick37Commented:
Try this. I had to comment out portions to check the flow, but both loops are entered:

Private Sub Command1_Click()
Dim nRet As Long
Command1.Enabled = False
Screen.MousePointer = vbHourglass
Do
  nRet = True 'AppActivatePartial(Trim("Login Welcome Message"))
    Debug.Print "AppActivatePartial(Trim(""Login Welcome Message""))"
    If nRet Then
      Title = Space$(256)
      nRet = True 'GetWindowText(nRet, Title, Len(Title))
      If nRet Then
        PauseTime = 10
        Start = Timer
          Do While Timer < Start + PauseTime
            DoEvents
          Loop
          Debug.Print "AppActivate ""Login Welcome Message"""
        Exit Do
      End If
    End If
Loop Until nRet <> 0

'SendKeys "~"
'SendKeys "{DOWN}"
'SendKeys "%{C}"
Debug.Print "SendKeys ""{W}"""
PauseTime = 15
  Start = Timer
    Do While Timer < Start + PauseTime
        DoEvents
    Loop
Debug.Print "SendKeys ""%{F}, {X}"""
Command1.Enabled = True
Screen.MousePointer = vbDefault
End Sub
0
 
Erick37Commented:
I think the key point here is to add DoEvents in the timer loops.  This allows your shelled application to work while the loop is running.
0
 
mcriderCommented:
Instead of doing the timer event, how about calling the Sleep API... Declare it like this:

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

Then you can do:


Sleep 15000

for a 15 second pause...


Cheers


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Erick37Commented:
Sleep may work.
But without DoEvents, you give up the ability of cancelling the operation if the shell fails.
0
 
mcriderCommented:
Eric37,

But deross is not checking the shell operation during the wait period...  The application is already active and deross doesn't have to do a DoEvent.

Sleep dispatches other programs while the sleep is waiting and performing a DoEvent can get you into trouble... Like executing the same subroutine more than once...


Cheers!
0
 
derossAuthor Commented:
Work's Great!

Thank you
0
 
mcriderCommented:
Glad I could help you... Please award the points... (hoping for a good grade ;-)


Cheers!
0
 
Erick37Commented:
Mcrider:
If you call Sleep after SendKeys, the keys will not be sent until *after* Sleep returns.  This could be a problem.

"The Sleep function allows you to specify the amount of time your applications are inactive. The DoEvents function returns control to the Visual Basic program after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent."

http://support.microsoft.com/support/kb/articles/Q158/1/75.asp
0
 
Erick37Commented:
Deross,
Which solution works for you?
0
 
mcriderCommented:
I have no problems using sendkeys with sleep.
0
 
derossAuthor Commented:
Eric,

Your solution worked just fine.
0
 
Erick37Commented:
But you awarded the points to Mcrider?
0
 
derossAuthor Commented:
Hi Erick,

I didn't realize I gave the points to Mcrider.  How do I award points to a particular person?
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now