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
derossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.