473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Application Parameters

I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?
Jun 27 '08 #1
11 5241
On 2008-04-21, Sergio <Se****@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?
Sure... You either use one of the overloaded versions of sub main:

Public Sub Main (ByVal args() As String)
Public Function Main (ByVal args() As String) As Integer

or...

You can get teh command line arguments from
System.Environment.GetCommandLineArgs or
System.Environment.CommandLine. Oh, yeah VB also has the
My.Application.CommandLineArgs property as well as the old VB Command
function. I believe that the My.Application.CommandLineArgs is the
recommended way now :)

--
Tom Shelton
Jun 27 '08 #2
Tom,
My.Application.CommandLineArgs property as well as the old VB Command
function. I believe that the My.Application.CommandLineArgs is the
recommended way now :)
\
Why?

In my idea is the My class only build to make it easier for old VB6 users.
That does in my idea not make it the recommended way.

The overloaded constructor is in my idea the normal way for this.

Cor

Jun 27 '08 #3
On Apr 22, 12:18 am, Sergio <Ser...@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?
Sergio,
You can launch your application with passing parameters using.
Generally, the parameters are passed when form's load event is fired.
So you can do;

You can get all the parameters that are passed on application startup;

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For Each x As String In Environment.GetCommandLineArgs
MsgBox(x)
Next
End Sub

Hope this helps,

Onur

Jun 27 '08 #4
On 2008-04-22, Cor Ligthert[MVP] <no************@planet.nlwrote:
Tom,
>My.Application.CommandLineArgs property as well as the old VB Command
function. I believe that the My.Application.CommandLineArgs is the
recommended way now :)
\
Why?
I meant that it is recommended over the Command function. In the
documentation, it cliams that the My method is faster and more
efficeint.
In my idea is the My class only build to make it easier for old VB6 users.
That does in my idea not make it the recommended way.

The overloaded constructor is in my idea the normal way for this.
The overloaded main is the way I handle it in C#, but if your using the
application framework in VB.NET, using the Main becomes a little more
difficult. I personally would use the System.Environment properties.

--
Tom Shelton
Jun 27 '08 #5
thanks Onur,

this works great, but always display one message (even if no parameters are
passed), the path of the .exe file, for ex: "c:\myApp\myApp.exe", any ideas?

Sergio.

"kimiraikkonen" wrote:
On Apr 22, 12:18 am, Sergio <Ser...@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?

Sergio,
You can launch your application with passing parameters using.
Generally, the parameters are passed when form's load event is fired.
So you can do;

You can get all the parameters that are passed on application startup;

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For Each x As String In Environment.GetCommandLineArgs
MsgBox(x)
Next
End Sub

Hope this helps,

Onur

Jun 27 '08 #6
Tom,

Jay B has once written all the possibilities he knew that there were with
with Sub Main in VB.Net (I thought that he was showing 12), I thought that
Armin and Herfried are never creating a real solution without that.

However as you know, only for the record.

Cor
"Tom Shelton" <to*********@YOUKNOWTHEDRILLcomcast.netschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
On 2008-04-22, Cor Ligthert[MVP] <no************@planet.nlwrote:
>Tom,
>>My.Application.CommandLineArgs property as well as the old VB Command
function. I believe that the My.Application.CommandLineArgs is the
recommended way now :)
\
Why?

I meant that it is recommended over the Command function. In the
documentation, it cliams that the My method is faster and more
efficeint.
>In my idea is the My class only build to make it easier for old VB6
users.
That does in my idea not make it the recommended way.

The overloaded constructor is in my idea the normal way for this.

The overloaded main is the way I handle it in C#, but if your using the
application framework in VB.NET, using the Main becomes a little more
difficult. I personally would use the System.Environment properties.

--
Tom Shelton
Jun 27 '08 #7
This is usual in most parameters reading API. Also the .NET doc says so :

(from
http://msdn2.microsoft.com/en-us/lib...dlineargs.aspx) :

Return Value
Type: array< System..::.String >[]()[]

An array of string where each element contains a command-line argument. The
first element is the executable file name, and the following zero or more
elements contain the remaining command-line arguments.

--
Patrice

"Sergio" <Se****@discussions.microsoft.coma écrit dans le message de
groupe de discussion : D7**********************************@microsoft.com...
thanks Onur,

this works great, but always display one message (even if no parameters
are
passed), the path of the .exe file, for ex: "c:\myApp\myApp.exe", any
ideas?

Sergio.

"kimiraikkonen" wrote:
>On Apr 22, 12:18 am, Sergio <Ser...@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application,
is
this posible? how?

Sergio,
You can launch your application with passing parameters using.
Generally, the parameters are passed when form's load event is fired.
So you can do;

You can get all the parameters that are passed on application startup;

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For Each x As String In Environment.GetCommandLineArgs
MsgBox(x)
Next
End Sub

Hope this helps,

Onur

Jun 27 '08 #8
On Apr 22, 7:39 pm, Sergio <Ser...@discussions.microsoft.comwrote:
thanks Onur,

this works great, but always display one message (even if no parameters are
passed), the path of the .exe file, for ex: "c:\myApp\myApp.exe", any ideas?

Sergio.

"kimiraikkonen" wrote:
On Apr 22, 12:18 am, Sergio <Ser...@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?
Sergio,
You can launch your application with passing parameters using.
Generally, the parameters are passed when form's load event is fired.
So you can do;
You can get all the parameters that are passed on application startup;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For Each x As String In Environment.GetCommandLineArgs
MsgBox(x)
Next
End Sub
Hope this helps,
Onur
Sergio,
Sure, it displays only your application's path if you didn't pass
additional parameters. Because first parameter refers to your
application's path, the rest are usually custom ones that you pass.

If you want to use a specific parameter, you may specify its index in
command-line argument array then use where you want(form's load on
example above). :-)

For example, if you want to get only second parameter which is your
custom parameter and its index is 1 ( zero is application's path,
remember), you may do;

' Start app like this
' c:\yourapp.exe param1 param2 param3
' To get param1
If Environment.GetCommandLineArgs().Length 1 Then
Dim my_params() As String = Environment.GetCommandLineArgs()
MsgBox(my_params(1))
End If

Use the same logic for param2, param3... for instance.

Hope this helps,

Onur Güzel
Jun 27 '08 #9
Thanks, finally i used

Environment.GetCommandLineArgs.GetValue(1)
"kimiraikkonen" wrote:
On Apr 22, 7:39 pm, Sergio <Ser...@discussions.microsoft.comwrote:
thanks Onur,

this works great, but always display one message (even if no parameters are
passed), the path of the .exe file, for ex: "c:\myApp\myApp.exe", any ideas?

Sergio.

"kimiraikkonen" wrote:
On Apr 22, 12:18 am, Sergio <Ser...@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?
Sergio,
You can launch your application with passing parameters using.
Generally, the parameters are passed when form's load event is fired.
So you can do;
You can get all the parameters that are passed on application startup;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For Each x As String In Environment.GetCommandLineArgs
MsgBox(x)
Next
End Sub
Hope this helps,
Onur

Sergio,
Sure, it displays only your application's path if you didn't pass
additional parameters. Because first parameter refers to your
application's path, the rest are usually custom ones that you pass.

If you want to use a specific parameter, you may specify its index in
command-line argument array then use where you want(form's load on
example above). :-)

For example, if you want to get only second parameter which is your
custom parameter and its index is 1 ( zero is application's path,
remember), you may do;

' Start app like this
' c:\yourapp.exe param1 param2 param3
' To get param1
If Environment.GetCommandLineArgs().Length 1 Then
Dim my_params() As String = Environment.GetCommandLineArgs()
MsgBox(my_params(1))
End If

Use the same logic for param2, param3... for instance.

Hope this helps,

Onur Güzel
Jun 27 '08 #10
On Apr 22, 8:52 pm, Sergio <Ser...@discussions.microsoft.comwrote:
Thanks, finally i used

Environment.GetCommandLineArgs.GetValue(1)

"kimiraikkonen" wrote:
On Apr 22, 7:39 pm, Sergio <Ser...@discussions.microsoft.comwrote:
thanks Onur,
this works great, but always display one message (even if no parameters are
passed), the path of the .exe file, for ex: "c:\myApp\myApp.exe", any ideas?
Sergio.
"kimiraikkonen" wrote:
On Apr 22, 12:18 am, Sergio <Ser...@discussions.microsoft.comwrote:
I need to pass two parameter to a vb.net 2003 windows form application, is
this posible? how?
Sergio,
You can launch your application with passing parameters using.
Generally, the parameters are passed when form's load event is fired..
So you can do;
You can get all the parameters that are passed on application startup;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For Each x As String In Environment.GetCommandLineArgs
MsgBox(x)
Next
End Sub
Hope this helps,
Onur
Sergio,
Sure, it displays only your application's path if you didn't pass
additional parameters. Because first parameter refers to your
application's path, the rest are usually custom ones that you pass.
If you want to use a specific parameter, you may specify its index in
command-line argument array then use where you want(form's load on
example above). :-)
For example, if you want to get only second parameter which is your
custom parameter and its index is 1 ( zero is application's path,
remember), you may do;
' Start app like this
' c:\yourapp.exe param1 param2 param3
' To get param1
If Environment.GetCommandLineArgs().Length 1 Then
Dim my_params() As String = Environment.GetCommandLineArgs()
MsgBox(my_params(1))
End If
Use the same logic for param2, param3... for instance.
Hope this helps,
Onur Güzel
Good alternative :)

However don't forget to put if conditional, because there may come up
situations that you need to start your app without passing your custom
parameter, then you'd better;

If Environment.GetCommandLineArgs().Length 1 Then
MsgBox(Environment.GetCommandLineArgs().GetValue(1 ))
End If

Regards,

Onur
Jun 27 '08 #11
On 2008-04-22, Cor Ligthert[MVP] <no************@planet.nlwrote:
Tom,

Jay B has once written all the possibilities he knew that there were with
with Sub Main in VB.Net (I thought that he was showing 12), I thought that
Armin and Herfried are never creating a real solution without that.

However as you know, only for the record.

Cor
Without access modifiers, it's something like:

Sub Main()
Sub Main(ByVal args() As String)
Function Main() As Integer
Function Main(ByVal args() As String) As Integer

Armin and Herfried probably don't use the application framework, either
:)

--
Tom Shelton
Jun 27 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Davies | last post by:
Hi I have a ASP and SQL Server website which uses a couple of Stored Procedures during the Shopping Cart process. 1 inserts the Customer information into a table and the next inserts the Payment...
7
by: Auto | last post by:
I starting to use Visual Studio .NET 2003 creating C# Windows application with SQL Server and I get problem with method Fill() for which when running ends with System Error even with the most...
3
by: Viktor Popov | last post by:
Hi, I would like to ask you do you know how to return a resultset and int value from Stored Procedure. If we have a table Teachers ========= ID INT PK NAME VARCHAR(25) ADDR VARCHAR(75)
5
by: vinoth | last post by:
Hi, I have created WindowsService Project.In that Project OnStart Method i have written the following Code. In this code the Server is waiting for the connection from client. When the Client...
1
by: Philip Townsend | last post by:
I am using the Microsoft Application Data Block and am getting the following error when trying to return a DataSet. Object must implement IConvertible Here is the code where the error occurs:...
2
by: Viktor Popov | last post by:
Hi, I use ASP.NET/C#/MS SQL and I'm trying to do the following but I find it very hard! I have Stored Procedure which saves data from the Application into DataBase. One of its parameters is...
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
3
by: mgsmario | last post by:
Hi Guys I have an ASP application that connects to an Oracle database, right now I'm trying to connect this same ASP application to a DB2 database (Express-C, version 9.5.0). I'm in the process...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.