Solved

Exiting a program spawned within another by sending keystrokes.

Posted on 2000-03-07
5
161 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:evansj
5 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 2593901
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
 
LVL 14

Accepted Solution

by:
mcrider earned 300 total points
ID: 2594257
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2594321
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
 

Expert Comment

by:ramanan
ID: 2594674
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2600150
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

19 Experts available now in Live!

Get 1:1 Help Now