Exiting a program spawned within another by sending keystrokes.

Help. I'm not up on VB. I recently recompiled a VB3 app that basically opens Paint Shop, pulls in a TGA, gamma corrects it, resizes it, then reduces the color depth, then saves it to the network. The app is called from within the vb app and fed keystrokes within a loop. That part works fine, except, the app (Paint shop pro) does not close at the end of the loop. It used to under 3.1, but now under 98 it creates a new copy of Paint shop pro with each iteration of the loop. Here is the significant code snippet that feeds the keystrokes:
Private Sub Timer1_Timer()
      RTime = RTime + 1
      Select Case RTime
     
         Case 10
            SendKeys "%CA2.1~"              ' Gamma Correct
           
         Case 15
            SendKeys "%IZ"                  ' Resize Image
           
         Case 20
            SendKeys "%4O"                   ' 640 x 480
           
         Case 25
            SendKeys "%CD5E~"               ' 256 Colors
           
         Case 55
            SendKeys "%FS"                  ' Save File As
            SendKeys "X:\FA\IMAGES\"        ' Save Directory for BMPs
            SendKeys Products.List(Prod_No) ' Product Directory
            SendKeys "\"
            SendKeys Prefixes.List(Pre_No)  ' Proper PreFix
            SendKeys "\"
            A = Trim(TGAs.List(TGA_No))     ' File Name
            A = Mid$(A, 1, Len(A) - 4)
            A = A & ".BMP"
            SendKeys A
            SendKeys "~"                    ' Save It
         
         Case 65
           SendKeys "%FXNNN"        ' Exit PaintShop
            Resize = False
            Timer1.Enabled = False
            RTime = 0
            Delay_Flag = False
      End Select
End Sub

What can I do to fix this?
evansjAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mcriderConnect With a Mentor Commented:
You can use API to close the application... See the following microsoft KB article:

HOWTO: Close Applications from Visual Basic
http://support.microsoft.com/support/kb/articles/Q153/4/63.asp?LNG=ENG&SA=MSDN&FR=0 


Cheers!®©
0
 
DalinCommented:
You may want to wait a couple of seconds after you send the save, before send the exit command, depends on the interval of the timer.

The other thing is make sure the Paintshop is the active App. Sendkeys will send to the app that currently has focus. Before the sendKeys, use the AppActivate statement.

0
 
Erick37Commented:
Also confirm that you can manually close PaintShop by pressing Alt-F-X-N-N-N.  If you are using a newer version, the commands may be different.
0
 
ramananCommented:
Check if the paintshop is already running and close any instance before opening.

Eg.
If Not xlApp Is Nothing Then
    For inti = 1 To        
        'xlApp.Workbooks.Close
    Next
Else
   Set xlApp = New Paintshop.Application
   
End If
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!®©
0
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.

All Courses

From novice to tech pro — start learning today.