• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1163
  • Last Modified:

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.
0
happytoo
Asked:
happytoo
  • 3
  • 3
  • 2
  • +1
1 Solution
 
kmorris1186Commented:
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...
0
 
Julian HansenCommented:
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
0
 
happytooAuthor Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Julian HansenCommented:
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.

0
 
happytooAuthor Commented:
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.
0
 
prashantagarw10Commented:
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
0
 
happytooAuthor Commented:
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.
0
 
prashantagarw10Commented:
ok buddy here we go :
1. declare three global variables.
2. In ur Sub Main store the values of each of the parameters into these public variables and then call this form using Application.Run as previously posted.
3. In the above Form_load event initialise the formletter and datafile variables from those public variables.

I hope this makes u comfortable and successful.

Cheers
Prashant
0
 
Julian HansenCommented:
It appears this question has received a number of valid answers.

I would recommend split points julianH and prashantagarw10

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now