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

x
?
Solved

How to define and launch command line items

Posted on 2003-10-27
14
Medium Priority
?
235 Views
Last Modified: 2010-05-03
Hi,

     I am wondering how I can launch items in a command line setting.  I am currently setting up a viewer for an application but I want to be able to launch the application with a command line parameter.  IE application.exe FILE.DAT

     Anyway to do this in VB 6.0?

Thx
Krelek
0
Comment
Question by:Krelek200
[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
  • 7
  • 3
  • 2
  • +1
14 Comments
 
LVL 11

Expert Comment

by:Steiner
ID: 9627293
Have a look at the Command-Function. To try it out, use the following code:

Private Sub Form_Activate()
  MsgBox Command  'This should show the parameters your app was called with
End Sub
0
 
LVL 1

Author Comment

by:Krelek200
ID: 9627334
But how do I define a string that takes the command line item?
0
 
LVL 9

Accepted Solution

by:
Dang123 earned 80 total points
ID: 9627569
You would assign the string returned from the Command function to a string variable in your program. You would then need to parse the string.

Based on your question you could use

Dim strFile as String


strFile = Command
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:Krelek200
ID: 9627583
I'll give it a shot
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
ID: 9627902
Just a couple quick comments:

You may not know that you can pass Command Line Parameters to your app in the IDE.  Select Project, then Properties and then switch to the Make tab.  There is a spot there to place your Command Line Parameters for testing.

This is the typical algorithm used to process command line arguments:
'---------------------------------------------------------------------------
Dim commandLine As String
Dim parameters As Variant
Dim a As Integer
   
commandLine = Command()
parameters = Split(commandLine) ' Splits using " " by default
For a = LBound(parameters) To UBound(parameters)
  Debug.Print "Parameter " & a & " = " & parameters(a)
Next a
'---------------------------------------------------------------------------

Some pitfalls I have seen with command line arguments:
If there are extra spaces between the parameters (which could occur if the program is called from the DOS prompt and somebody is typing in the command line), the split function will give each space its own place in the array.  You can eliminate these kind of problems by checking the length of each parameter like so:
'---------------------------------------------------------------------------
Dim commandLine As String
Dim parameters As Variant
Dim a As Integer, b As Integer
   
b = 0
commandLine = Command()
parameters = Split(commandLine) ' Splits using " " by default
For a = LBound(parameters) To UBound(parameters)
    If Len(Trim(parameters(a))) > 0 Then
        b = b + 1
        Debug.Print "Parameter " & b & " = " & parameters(a)
    End If
Next a
'---------------------------------------------------------------------------

Also, if you call your viewer programmatically from another app, it is possible that you will pass a full path name to the file to be viewed.  If so, you may have spaces in the path leading up to your file name.  Obviously, when you parse the command line, the path/filename will get split into two different parts.  To avoid this, always convert a fully qualified path to use short filenames, thus removing any spaces.

Hope this helps out.  Happy Coding...
0
 
LVL 1

Author Comment

by:Krelek200
ID: 9628863
What do you put in the command line parameters to enable them.  I am having some trouble with the Make tab about the parameters.
Krelek
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9628912
You should just need to put the line as the user would type it after your program name. What trouble are you having?

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9628984
It is the second box from the bottom on the make tab labeled "Command Line Arguments:"

If you were to put "planets.jpg shuttle.jpg /slideshow" in the box, then this would be the equivalent of running your app from the command line like this:

yourAppName.exe planets.jpg shuttle.jpg /slideshow

That's it.
0
 
LVL 1

Author Comment

by:Krelek200
ID: 9629360
It works inside of Visual Basic but when I create the EXE file it states that it cannot load one of its components.  Do you have to specify the like this:

C:\direct\direct\myAppName.exe C:\direct\direct\fileToLoad.Ext

Thanks
Krelek
0
 
LVL 1

Author Comment

by:Krelek200
ID: 9629441
I understand the comment about converting a fully qualified path to use short filenames.  Now how do I handle these long strings that is created?

Thx
Krelek
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9629641
Does the error occur during the compile in the IDE or when you run the .exe directly?

What are you using to create the short filenames, what are your storing them in, and where do you want them to go?
0
 
LVL 1

Author Comment

by:Krelek200
ID: 9630112
I have solved the error problem.  I am storing them in a subdirectory that is short (8) letters long.  I believe that is waht you meant by short filenames.

Thx
Krelek
0
 
LVL 11

Assisted Solution

by:Steiner
Steiner earned 80 total points
ID: 9631788
Just my 2cents: If you only want exactly 1 parameter for your app (eg. 1 file with full path), then you can forget about splitting the command-string and also about long and short file names. Just take the string as it comes.
I guess the main problem about the long filenames is, that these may contain spaces which are then used to split the string because your app thinks that beyond the space comes a new argument.
0
 
LVL 1

Author Comment

by:Krelek200
ID: 9635837
Thanks you all.  I have got things working the way it should
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
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