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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture parameter passed to a program 1

Status
Not open for further replies.

mikej336

MIS
Feb 10, 2005
164
US
Anouther Newbie question.

I need to capture a parameter passed to a program in a variable.

Ex

hello.exe 43454354

I am using VB.Net 2005 Express.

Thanks

Uncle Mike



 
I found

Private Sub ParseCommandLineArgs()
Dim inputArgument As String = "/input="
Dim inputName As String = ""

For Each s As String In My.Application.CommandLineArgs
If s.ToLower.StartsWith(inputArgument) Then
inputName = s.Remove(0, inputArgument.Length)
End If
Next

If inputName = "" Then
MsgBox("No input name")
Else
MsgBox("Input name: " & inputName)
End If
End Sub

but it appears to be part of ConsoleApplicationBase not sure if it can only be called as part of a console or if it will work with a GUI program.

Uncle Mike

 
Simple enough it just took 5 hours on the internet to find it...

Dim args As String

For Each args In My.Application.CommandLineArgs
MsgBox("My arguments is " + args)
Next


Perhaps someone else will find this and it will help the.

Some of the documentation says this requires .net 2.0.

I also thought it might be required to be the start up some where but his worked from a button...


Uncle Mike
 
Start your application with a Sub Main from a module, and define Sub Main like this:

Code:
Module Module1
  Public Sub Main(args() As String)
    For Each arg As String In args
      'Do something
    Next
  End Sub
End Module

The args() array is a String array containing all arguments passed while running the application. Doing it this way, you can even choose to run different forms at startup, depending on commandline arguments.

Regards, Ruffnekk
---
Is it true that cannibals don't eat clowns because they taste funny?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top