?
Solved

Exiting a program spawned within another by sending keystrokes.

Posted on 2000-03-07
5
Medium Priority
?
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 900 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

770 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