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!

Passing Arguements to VB 2005 Console Application 1

Status
Not open for further replies.

TheVillageIdiot27

Programmer
Nov 10, 2005
58
GB
I am sure this must be quite straight forward but I can't seem to find an example on the net.

I have half written a console application to export a crystal report as a pdf, but want to be able to pass the input report, output pdf, and any report parameters from a batch file so it might look something like...

Code:
exportreport.exe  / input="i:\myreports.rpt" output=c:\test.pdf

If someone was able to let me know what the VB was which would go with the above to populate strInput and strOutput I would appreciate greatly.

Thanks in advance
 
I don't think this is dependent on a form. Look at:
Code:
Microsoft.VisualBasic.Command

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
I've modified your commandline syntax slightly to simply things:

[tt]/input="Input File" /output="Output File"[/tt]


In other words spaces are only allowed between quotes and each parameter is preceeded by the forward slash /


You will need to more thoroughly validate, but this does work and should show you the principle:

Code:
Module Module1

	Private strInput As String = String.Empty
	Private strOutput As String = String.Empty

	Sub Main(ByVal Params() As String)

		For a As Integer = 0 To Params.Length - 1
			Console.WriteLine(Params(a))
		Next

		If Params.Length <> 2 Then
			Console.WriteLine("2 parameters are required")
		Else
			Dim p1() As String = Params(0).Split("="c)
			Dim p2() As String = Params(1).Split("="c)
			If p1(0) = "/input" Then strInput = p1(1).Replace("""", "")
			If p1(0) = "/output" Then strOutput = p1(1).Replace("""", "")
			If p2(0) = "/input" Then strInput = p2(1).Replace("""", "")
			If p2(0) = "/output" Then strOutput = p2(1).Replace("""", "")
			If strInput = String.Empty OrElse strOutput = String.Empty Then
				Console.WriteLine("input and output parameters are required")
			Else
				'do whatever with strInput and strOutput
				Console.WriteLine("Input: " + strInput + ", Output: " + strOutput)
			End If
		End If
		Console.ReadLine()

	End Sub

End Module


Hope this helps.


[vampire][bat]
 
Ignore this:

Code:
        For a As Integer = 0 To Params.Length - 1
            Console.WriteLine(Params(a))
        Next

That was some test code that I put in to check the parameters, you wont need it.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top