Solved

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

Posted on 2004-09-22
11
1,145 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
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
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
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:happytoo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 51

Expert Comment

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

I would recommend split points julianH and prashantagarw10

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
EvenOdd challenge 10 81
squareUp  challenge 22 104
seriesUp challenge 7 105
Image decoding from Camera 3 42
A short article about problems I had with the new location API and permissions in Marshmallow
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.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

762 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

10 Experts available now in Live!

Get 1:1 Help Now