Solved

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

Posted on 2004-09-22
11
1,147 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
11 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 54

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 54

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 250 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 54

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
iframe detection of parent window scale 20 70
Please help| Getting the syntax error in below query. 2 56
Delphi: barcode reading on android platform 1 26
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now