Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-22
11
Medium Priority
?
1,157 Views
Last Modified: 2006-11-17
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
Comment
Question by:happytoo
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 7

Expert Comment

by:kmorris1186
ID: 12127651
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
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 12131307
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
 

Author Comment

by:happytoo
ID: 12133188
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Julian Hansen
ID: 12133266
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
 

Author Comment

by:happytoo
ID: 12136001
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
 
LVL 5

Expert Comment

by:prashantagarw10
ID: 12136875
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
 

Author Comment

by:happytoo
ID: 12137226
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
 
LVL 5

Accepted Solution

by:
prashantagarw10 earned 750 total points
ID: 12137589
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
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 12400596
It appears this question has received a number of valid answers.

I would recommend split points julianH and prashantagarw10

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question