Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Calling an .exe file in VB

Posted on 2005-03-05
Medium Priority
Last Modified: 2010-05-02

We have a Java program called Test that has a textbox on it.  The user would enter a path and then press the Enter key.  The path will then be used to process other commands in the application.  

Now, we converted our Java application into an .exe file.  We then want to call this file in a VB application by using Shell.  Our syntax goes like this:

a = Shell("Test.exe")
AppActivate a
SendKeys "C:\TestFile.pdf"
SendKeys "{Enter}"

The textbox (in the Java app) receives the focus when the program is loaded.  However, the program doesn't work.  What do I need to make it work?

Thanks in advance!

Question by:akeena_g

Accepted Solution

plq earned 600 total points
ID: 13465368
Wouldn't it be better to make your EXE accept a command line argument

Then you can do

a = Shell("Test.exe C:\TestFile.pdf")

sendkeys is considered bad programming, and often leads to problems and unreliability
LVL 17

Expert Comment

ID: 13465491
I would go with plq's suggestion with one small addition, if you had a long file names it is better to use double quotes:

a = Shell("Test.exe ""C:\TestFile.pdf""")

Author Comment

ID: 13468900
How exactly can I make my exe prog accept a command line argument?

Expert Comment

ID: 13469264
try following

  ReturnValue = Shell("NOTEPAD.EXE", 1)
  AppActivate ReturnValue
  SendKeys "Hello"
  SendKeys "{Enter}"

hope it helps,

LVL 22

Assisted Solution

JesterToo earned 600 total points
ID: 13469325
I am assuming it is still a Java app and was converted to a windows exe by something like "exe4j".  If so, you just need to add some code to your main method in the startup class module like this:

         public class Appname {
           public static void main (String[] args) {
               if (args.length < 1) {
                  System.out.println ("usage: Appname <filename>");
            } else {
                  String fileName = args[0];
               yada yada yada...

replace the existing logic that expects the filename to be entered on screen.  


Featured Post

Independent Software Vendors: 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

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

571 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