Command Line Arguments for a Non Command Line Program?

C

CMG

Hi,

I have been looking for this quite some time now. I want
to be able to pass along a string of data into my
compiled programs, like prog.exe "myvar1" "myvar2" etc.
or prog.exe /f whatever /g whatever.

Anny ideas? Is this at all possible? If not, i think i
should really quit VB :( This is like the 20th thing i
wanna be able to do but can't do in vb.net :-/
 
S

solex

Do you have the help file that comes with VS.NET?

Here is the sample right from the help

Function Main(ByVal CmdArgs() As String) As Integer
Dim ArgNum As Integer ' Index of individual command-line argument.
If CmdArgs.Length > 0 Then ' See if there are any arguments.
For ArgNum = 0 To UBound(CmdArgs)
' Examine CmdArgs(ArgNum) for settings you need to handle.
Next ArgNum
End If
MsgBox("Hello World!") ' Display message on computer screen.
Return 0 ' Zero usually means successful completion.
End Function
 
C

CMG

I don't know what to say...actually i do:

1st: i am so sorry, seems like the one place i didn't
think to find help was in the help file, tried MSDN (hard
to find annything there, but there are a few topics that
are good), google (found about 10 million pages, cus i
did not know how to name it actually, so i could not do a
specific search), tried www.planet-source-code.com (bout
90% is crap, but there are also verry, verry good things
there).

2nd: Thank you verry, verry much for pointing this out to
me and actually showing it to me.

3rd: Thank you!

4th: Did i say thank you?

and 5th: In case i forget: THANK YOU!
 
T

Tom Shelton

I get NO Accessable Main Method with an apropriate
signature was found...

If you put this in a form... It should be:

Public Shared Sub Main(ByVal Args() As String)
End Sub

Alternatively, it can be a function if you want to return an exit code
to the OS:

Public Shared Function Main(ByVal Args() As String) As Integer
....
Return 0
End Function

Or, you can do this using the System.Environment class, and skip the
main if you like:

Dim Args() As String = System.Environment.GetCommandLineArgs()

For Each Arg As String In Args
MessageBox.Show(Arg)
Next

Or, you can get it as one unparsed string:

MessageBox.Show(System.Environment.CommandLine)

HTH
 
S

solex

CMG

If you take the function below and place it in it's own module say "Start"
then in the project properties under \Common Properties\General make the
Startup Object equal "Start", you should not have a problem.

Dan
 
C

CMG

Thank you so much for awnsering this whithout turning me
into flame bait :)

The truth is, i learned most of this on my own, and have
recently started a self study VB.NET, and actually just
never, ever did something with sub main... I tested it,
and it works like i thought, so i'm verry happy one of
the things i wanted now finally works :)

Now all i have to do is see how i could add my program to
the rightclick event of my mouse when the file extention
is .sfv, or that my program get's opened when i open
a .sfv file, and that the full path get's passed along to
the main executable.


So: THANK YOU! :)
-----Original Message-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top