Solved

Exiting a program spawned within another by sending keystrokes.

Posted on 2000-03-07
5
160 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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