A common news group question goes something like:
How can I pass arguments to my application?
The Command function retrieves information from the command line. It makes the information available to your application. I have seen the question posted so many times in news groups that I decided to write a demo program and show how to use the function. So, here it is, the tip-of-the-month.
Returns the argument portion of the command line used to launch Microsoft Visual Basic or an executable program developed with Visual Basic.
When Visual Basic is launched from the command line, any portion of the command line that follows
/cmdis passed to the program as the command-line argument. In the following example,
cmdlineargsrepresents the argument information returned by the Command function.
VB /cmd cmdlineargs
For applications developed with Visual Basic and compiled to an .exe file, Command returns any arguments that appear after the name of the application on the command line. For example:
I wrote a demo program to demonstrate the use of the function. A screen shot of the VB6 demo:
In this example the command line contains three arguments. The arguments are parsed from the command line and displayed in the text boxes. This sample was run from the VB IDE. The command information was entered via the project properties 'make' dialog, for example:
A modified Make dialog - see Make VB's Dialog Boxes Larger.
I compiled the 'application' [included in the zip file] and ran it from a DOS console. Arguments are entered on the command line, for example:
The Demo Program Uses This Module
Module - Click for More Info Description Used in the Demo To modConnectToWebSite.bas Connect to a web site Show this info when Help/Info is
selected from the demo.
Download VB 6 Source Code
Click here to download the VB 6 source code [13k]
Previous Tip Tip Index Next Tip First Tip