[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Exiting a program spawned within another by sending keystrokes.

Posted on 2000-03-07
5
Medium Priority
?
166 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

656 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