473,406 Members | 2,467 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,406 software developers and data experts.

Nammed Arguments in VB.NET??

Hello All,

I onced used a very efficient method in VBScript to retrive nammed arguments
passed on the commanline using:
WScript.Arguments.Named.Item ("ArgumenName").

That is, the call to the script would be somthing like:
script.wsf /ArgName:"Value of argument"

Does anyone know if there is an equivalent in VB.NET?

BTW: I am currently using System.Environment.GetCommandLineArgs and I have
also used the Main (args()) constructor...

Any comments are greatly appreciated!
Hanika
Nov 21 '05 #1
3 3764
Hanika,
I don't know of any pre-built functionality, however it should not be that
hard to create something:

For example you could use a regular expression to parse each parameter.

Something like:

Imports System.Text.RegularExpressions

Const pattern As String = "^/(?<name>\w+)(?:\:(?<value>.+)$|$)"
Dim argRegEx As New Regex(pattern, RegexOptions.Compiled)
For Each arg As String In Environment.GetCommandLineArgs()
Debug.WriteLine(Nothing, arg)
Debug.Indent()
With argRegEx.Match(arg)
If .Success Then
Debug.WriteLine(.Groups("name"), "name")
Debug.WriteLine(.Groups("value"), "value")
End If
End With
Debug.Unindent()
Next

I would consider encapsulating the above in a class where I populate a
HashTable with the name/value pairs.

Of course you could use standard String functions to parse each parameter
also:

For Each arg As String In Environment.GetCommandLineArgs()
Debug.WriteLine(Nothing, arg)
Debug.Indent()
If arg.StartsWith("/") Then
Dim index As Integer = arg.IndexOf(":"c)
Dim name As String
Dim value As String
If index <> -1 Then
name = arg.Substring(1, index - 1)
value = arg.Substring(index + 1)
Else
name = arg.Substring(1)
value = String.Empty
End If
Debug.WriteLine(name, "name")
Debug.WriteLine(value, "value")
End If
Debug.Unindent()
Next

Hope this helps
Jay
"Hanika" <Ha****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello All,

I onced used a very efficient method in VBScript to retrive nammed
arguments
passed on the commanline using:
WScript.Arguments.Named.Item ("ArgumenName").

That is, the call to the script would be somthing like:
script.wsf /ArgName:"Value of argument"

Does anyone know if there is an equivalent in VB.NET?

BTW: I am currently using System.Environment.GetCommandLineArgs and I
have
also used the Main (args()) constructor...

Any comments are greatly appreciated!
Hanika

Nov 21 '05 #2
Hanika,
Here's an improved Pattern to replace the one from my earlier post:

Const pattern As String = "^/(?<name>\w+)(?:\:(?<value>.+)$|\:$|$)"

This pattern will match the following:

/ArgName:"Value of argument"
/ArgName
/ArgName:

Note the regular command line parser will interpret the quotes on the first
one, making it appear as:

/ArgName:Value of argument

In the collection returned from GetCommandLineArgs.

Hope this helps
Jay

"Hanika" <Ha****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello All,

I onced used a very efficient method in VBScript to retrive nammed
arguments
passed on the commanline using:
WScript.Arguments.Named.Item ("ArgumenName").

That is, the call to the script would be somthing like:
script.wsf /ArgName:"Value of argument"

Does anyone know if there is an equivalent in VB.NET?

BTW: I am currently using System.Environment.GetCommandLineArgs and I
have
also used the Main (args()) constructor...

Any comments are greatly appreciated!
Hanika

Nov 21 '05 #3
This great thanks!
Hanika

"Jay B. Harlow [MVP - Outlook]" wrote:
Hanika,
Here's an improved Pattern to replace the one from my earlier post:

Const pattern As String = "^/(?<name>\w+)(?:\:(?<value>.+)$|\:$|$)"

This pattern will match the following:

/ArgName:"Value of argument"
/ArgName
/ArgName:

Note the regular command line parser will interpret the quotes on the first
one, making it appear as:

/ArgName:Value of argument

In the collection returned from GetCommandLineArgs.

Hope this helps
Jay

"Hanika" <Ha****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello All,

I onced used a very efficient method in VBScript to retrive nammed
arguments
passed on the commanline using:
WScript.Arguments.Named.Item ("ArgumenName").

That is, the call to the script would be somthing like:
script.wsf /ArgName:"Value of argument"

Does anyone know if there is an equivalent in VB.NET?

BTW: I am currently using System.Environment.GetCommandLineArgs and I
have
also used the Main (args()) constructor...

Any comments are greatly appreciated!
Hanika


Nov 21 '05 #4

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

Similar topics

9
by: Chuck Anderson | last post by:
I have a function with 7 inputs. The last three have default values. I want to call that function specifying the first four, skip two and then specify the last. I thought I could write this...
9
by: Matt Eberts | last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object instantiated via a constructor using the arguments object and have it expanded, so to speak, so that it doesn't appear as...
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
41
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
7
by: sfeher | last post by:
Hi All, Is there a way to preserve the arguments across functions? I have: <script> function myFirstFunction() { // arguments = 'param1'
36
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
2
ADezii
by: ADezii | last post by:
When a call is made to a Sub or Function Procedure, you can supply Arguments in the exact order they appear in the Procedure's definition, or you can supply them in any position by name. To...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.