Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Startup Params

Status
Not open for further replies.

gavjb

Technical User
Jul 5, 2005
67
GB
Hi,

I am fairly new to VB, and am trying to create a small application, which needs to be run though a command prompt or a shortcut with a parameter passed to it.

For example you could run it as something like this

update.exe /updatefile="c:\myupdate.upd"

Can anyone tell me how/if I can create an VB6 app to except a paramter passed to it on startup.

Thanks,


Gavin,
 
You can do this. To see how it works, I suggest you test this on a "fresh" vb project.

Open VB, create a standard exe project
Put a button on the form
In the click event, put this code.

Code:
Private Sub Command1_Click()
    
    MsgBox VBA.Command

End Sub

If you start the project and click the button, you'll notice that the message box window is empty because you haven't specified any command line arguments.

You could compile the project to an EXE and then call it with command line parameters to make sure it's working the way you think it should.

You could also test this from within the VB IDE. To do this... Click Project -> Properties. Click on the MAKE tab. There is a section where you can enter command line arguments for testing purposes.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
The VBA isn't necessary, it is loaded into the global namespace in VB5/6. If you inadvertantly overload Command() of course (such as by declaring a Sub/Function of that name) you may need the qualification.

This is also actually a function/method, not a property:

[tt]MsgBox Command$()[/tt]

.. but VB is very tolerant of syntax in such cases.

A more important question is whether you really want a "Windows" (GUI) EXE or a "Console" (command line) EXE. By default VB5/6 only create the former. It doesn't take much work to use VB to create console programs however. Check the FAQs in the VB forums or a few searches of the forum threads or even Google.
 
Thanks for all your help, the project I am looking for this for has been put on hold at the moment, but this will be very useful for me when it resumes later this year.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top