|
-
Aug 20th, 2000, 04:10 PM
#1
Thread Starter
Lively Member
This is the example that MSDN provided for COMMAND().
What is COMMAND() and how do you use this Function below?
Thanks
Code:
Function GetCommandLine(Optional MaxArgs)
'See if MaxArgs was provided.
If IsMissing(MaxArgs) Then MaxArgs = 10
'Make array of the correct size.
ReDim ArgArray(MaxArgs)
Dim InArg, NumArgs
NumArgs = 0: InArg = False
'Get command line arguments.
Dim CmdLine, CmdLnLen
CmdLine = Command()
CmdLnLen = Len(CmdLine)
Dim C, I
'Go thru command line one character
'at a time.
For I = 1 To CmdLnLen
C = Mid(CmdLine, I, 1)
'Test for space or tab.
If (C <> " " And C <> vbTab) Then
'Neither space nor tab.
'Test if already in argument.
If Not InArg Then
'New argument begins.
'Test for too many arguments.
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
'Concatenate character to current argument.
ArgArray(NumArgs) = ArgArray(NumArgs) & C
Else
'Found a space or tab.
'Set InArg flag to False.
InArg = False
End If
Next I
'Resize array just enough to hold arguments.
ReDim Preserve ArgArray(NumArgs)
'Return Array in Function name.
GetCommandLine = ArgArray()
End Function
-
Aug 20th, 2000, 04:22 PM
#2
Fanatic Member
Command() just returns all the command line parameters. If your program is called myprog.exe and the user typed in dos:
myprog hello
then Command() would return "hello"
-
Aug 20th, 2000, 04:45 PM
#3
well, when you make your filetype associated with your program, Command returns the path of the file that is being opened, the problem is, it has quotes around the name so you have to replace the quotes with spaces, then trim the spaces(via Replace and Trim).
-
Aug 20th, 2000, 05:00 PM
#4
Thread Starter
Lively Member
Can you show me how the example above works? or make your own example and show me.
thank you Oetje and Denniswrenn
-
Aug 20th, 2000, 05:48 PM
#5
Code:
Private Sub Form_Load()
Dim FF As Integer
Dim FName As String
FF = FreeFile
If Command$ <> "" Then
FName = Replace(Command$, Chr$(34), " ")
FName = Trim$(FName)
FF = FreeFile
Open FName For Input As FF
txtText = Input(LOF(FF), FF)
Close FF
End If
End Sub
-
Aug 21st, 2000, 01:49 AM
#6
Thread Starter
Lively Member
Thanks Dennis but how do i test this? I ran the program but it didn't do anything.
And why would someone use COMMAND()?
[Edited by James Bond 007 on 08-21-2000 at 02:55 AM]
-
Aug 21st, 2000, 01:52 AM
#7
that is because you have to associate a file type with your program.
then double click the filetype(after it is associated) and it should work.
see this Tip on details how to associate a filetype with your program.
-
Aug 21st, 2000, 01:57 AM
#8
OH: I forgot one thing, you are going to have to make an exe out of your program to associate it....
a quick way to associate your program with a file is to make a file with an unknown extension,
for example....
MyFile.007
then double click that file, a box saying
"Open With..." will appear,
there will also be a list box, your program shouldnt be in the list box, instead, choose to browse for your program, then tick the box that says "always open with this program"
and `viola
simple.....
-
Aug 21st, 2000, 02:00 AM
#9
Thread Starter
Lively Member
What am I suppose to associate with?
I tried Ojtie and it gave me an error of 53.
-
Aug 21st, 2000, 02:02 AM
#10
The reason one would use Command is so you can retrieve the command line parameters, for example, if you wanted to run your program from a dos prompt and typed
c:\windows\desktop\pathtofile>MyFile -param
you would check for "-param" and if it was a valid parameter you would do something.
you can look at an example of a program using command line parameters here:
http://www.winamp.com/nsdn/winamp2x/dev/sdk/api.jhtml
the Command function can also be used for what I described to you,
for getting the path to a file that was double clicked.
-
Aug 21st, 2000, 02:17 AM
#11
Thread Starter
Lively Member
So young and talented.
Thanks Dennis! I finally got working when you gave me that example with a test file call myfile.007 and associated with my own program.
I put in some info in myfile.007 and double click on it, and my program came up with that info. Is that what it suppose to do?
Thanks for your help.
-
Aug 21st, 2000, 02:21 AM
#12
Yep!
I put in some info in myfile.007 and double click on it, and my program came up with that info. Is that what it suppose to do?
that means it worked 
pat yourself on the bad Mr. Bond, because... well i dont know why you should pat yourself on the back, but just do it 
-
Aug 21st, 2000, 08:22 AM
#13
You can also retrieve multiple command line arguments by using the Split() function.
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
|