|
-
April 20th, 2005, 10:12 AM
#1
Passing in Command Line Arguments [VB6]
My VB6 application is meant as a command line application (to be run from the command prompt).
The way I implemented that was to create a blank/invisible form (frmMain) and put all my code in there (this should work when run from the command line right?)
What I need to implement is the ability for the user to pass in an argument when running the application from the command line.
Specifically, currently my application gets Today's date [String sDate], I need this to be more flexible, meaning I want the user to be able to select the date by passing it in.
So, for example, if my application is called [app.exe] and from the command prompt the user runs "app.exe" [with no arguments] my [sDate] will work as it does now.
HOWEVER if the user did something like "app.exe 03202005" then I want sDate to be 03202005 (forget Formatting Date issues, assume it is a string).
How can I accomplish this?
[Also, if you know, how can I make my VB6 application into an EXE?]
-
April 20th, 2005, 12:41 PM
#2
Re: Passing in Command Line Arguments [VB6]
Hi there,
you can use the Command function.
Command returns the command line arguments to your
programm if any! For example in your case:
Code:
dim strArgs as String
strArgs = Command
...
and so on...
You can make your VB application an EXE by selecting File->Projekt1.exe make
(it was something like this, my version of visual studio is in german )
best regards,
typecast
-
April 20th, 2005, 02:06 PM
#3
Re: Passing in Command Line Arguments [VB6]
If you don't want any forms in your program, you ought to create a module with a "Main" sub.
Code:
Private Sub Main()
...
End Sub
Then go to Project/*Project Name* Properties/Startup Object and select "Sub Main". Your program will then start at sub main and not have any forms.
The Strawdog's out in the street
-
April 21st, 2005, 01:55 AM
#4
Re: Passing in Command Line Arguments [VB6]
When you pass something from the Command Line to the VB app (compiled), the arguments that are passed get stored into Command$. You can use this variable to get the Command Line Arguments passed by the user
e.g; If the user writes something like this
myapp.exe 04212005 myName
then you can get these arguments by parsing the command$ variable
here is a sample source code...
Code:
Option Explicit
Public Sub main()
'Store command line arguments in this array
Dim sArgs() As String
Dim iLoop As Integer
'Assuming that the arguments passed from
'command line will have space in between,
'you can also use comma or otehr things...
sArgs = Split(Command$, " ")
For iLoop = 0 To UBound(sArgs)
'this will print the command line
'arguments that are passed from the command line
Debug.Print sArgs(iLoop)
Next
End Sub
hope this helps....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|