Link to home
Start Free TrialLog in
Avatar of happytoo
happytoo

asked on

How to pass parameters to an executable vb.net program?

Hello,

I have an executable vb.net program and I need to pass multiple parameters.  How do I go about it.  Please help.  Thanks.
Avatar of kmorris1186
kmorris1186

Check this site out..

It uses the Command() function to get the Command line options.

http://www.devx.com/dotnet/Article/10115/1763

this is the same way it was done in VB 6.0.  There might be an easier way in .NET...
Avatar of Julian Hansen
Trye GetCommandLineArgs

Example (From MSDN help on GetCommandLineArgs)

Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      '  Invoke this sample with an arbitrary set of command line arguments.
      Dim arguments As [String]() = Environment.GetCommandLineArgs()
      Console.WriteLine("GetCommandLineArgs: {0}", [String].Join(", ", arguments))
   End Sub 'Main
End Class 'Sample
Avatar of happytoo

ASKER

I'm sorry, I'm new with VB.NET, but do I need to create another vb.net source code like you mentioned above to process this function.  I think what I'm trying to do is this:

The batch file needs to call exe residing on server from a client machine and pass some parameters to the exe or vb.net windows application.  

Many thanks.
Hi happytoo

Can you explain what you mean by

>The batch file needs to call exe residing on server

What batch file are we talking about.

Can you give some more detailed information of what you are looking for - at present it is a bit vague.

Ok, here's what I'm looking for.

I have an executable vb.net program called "mergeletter.exe".  I have 3 parameters that I needed to pass. Param1 Param2 Param3.  How can my vb.net program retrieve these parameters?  Can you give me some ideas, sample codes perhaps.  I new with VB.net so I'm not really familiar with it.  If you can just show me show me how to code them that'll be really helpful for me.  Thanks.
Add this code to any of ur forms and change ur project's startup to Sub Main and in that call ur startup form as i have called Form1. the args is an array of arguments.
Shared Sub Main(ByVal args() As String)
            MessageBox.Show(args(0))
            Application.Run(New Form1)
End Sub

However after this to run project from ur .Net IDE u must go to project properties and then to configuration properties and there set the value of startup parameters. this is just for debugging, when u actually run the application u must pass arguments as command line arguments
I'm sorry but I don't understand this.  I thought it was just simply GetCommandLineArgs statement.  I'm actually pulling the actual data of PARAM1 PARAM2 PARAM3 from a Database.  Here is my actual vb.net script.

Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim wrdapp As Object
            Dim formletter As String
            Dim datafile As String

            formletter = "C:\LETTERS\formletter.doc"
            datafile = "C:\LISTS\testdata.csv"


            wrdapp = CreateObject("Word.Application")
            wrdapp.Documents.Open(formletter).MailMerge.OpenDataSource(datafile)
            wrdapp.Visible = True
            wrdapp.ActiveDocument.MailMerge.Execute()
            wrdapp.ActiveDocument.Printout()
            wrdapp.Documents(formletter).Close(False)
            wrdapp.Quit()
        Catch Ex As Exception
            MessageBox.Show("Unable to complete" & vbCrLf & Ex.Message)
        End Try
    End Sub
End Class

The Formletter and Datafile are the parameters which I'm adding 1 more parameters.  

Hope this helps explaining my issue.  Thanks for all your help.
ASKER CERTIFIED SOLUTION
Avatar of prashantagarw10
prashantagarw10

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It appears this question has received a number of valid answers.

I would recommend split points julianH and prashantagarw10