The function you are looking for is "Command", which will retrieve any parameters passed to the program. I don't quite seem to recall if the program needs to be compiled (made into an exe) before it will work in your code... but a here is a small example that should display everything passed to your program:
msgbox command$
Yeah, That's Right, it's just that simple. Then you can run a test on the passed command function with a select case or even a simple if. It becomes slightly more complicated when you want to read more than 1 command line argument, because the entire command line is passed to command$ as a string, so if you wanted to do something like:
yourproject.exe /width=10 /height=10 /nosound
Then you would have to rip apart the command line by each space, and work with them accordingly. A Real easy solution to that is to use split to gather each item into an array like so:
dim Args() as string
Args = split(Command$, " ")
' /* Now Args Is An Array Containing Each Item */
for each Arg in Args
msgbox Arg
next Arg
Hope this helps, and let me know the outcome.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Absolutely! Just to ensure I Built a Quick Test Program:
Private Sub Form_Load()
Dim X(2)
X(0) = "hi"
X(1) = "bye"
X(2) = "end"
For Each word In X
MsgBox word
Next word
End Sub
Works Great. I was amazed too, after having coded Perl for some time, I found myself using for each's in VB, and correcting myself to using ubound.... and one day I said "hmn..." and it worked. Saved me a lot of pain. Just for future reference, you can use it on collections and Arrays.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
I have been coding VB since windows 3.1, and to be perfectly honest, I've never used an option explicit. In most cases I don't actually declare it with a full layout, (perhaps my Qbasic days kicking in) but more times than not, I use the symbol identifiers (this is in my own code, since most modern day programmers would get too confused by the symbol identifiers). I just find it easier to say:
dim words$
Less Typing and if you know that $ is the symbol for string, it's more clear throughout the rest of the code as well. Also, if you happen to be a big API Fan (Like myself) the API will take dump on variables passed to it, that are not of the proper type.... again, this helps the layout of the API Call (using variable identifiers) because you see what you are passing into the function. For example purposes, I don't declare them usually or even identify them (variables) because it's not code that's going into production, but for code that I release, or code that is built for a company, for the sake of speed and the avoidance of memory leaks in code, I make sure that every thing is declared.
In fact, for those reading who are interested:
$ = String
% = Integer
& = Long
! = Single
# = Double
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Right, And not having a good understanding of what your variables are doing (defining them certainly helps with that) leads to real nasty code, and triples your pain in debugging.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215