Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 55 / 68

Receiving command-line arguments

This lesson covers receiving command-line arguments in VB.NET, with the aim of passing values in from outside at run time.

Declaring Sub Main(args As String()) gives the Main procedure a string array holding the command-line arguments — the mechanism for passing options and parameters in when the program starts.

The sample code checks whether arguments arrived with args.Length > 0, using args(0) as the name if so and a fallback if not, deciding between them with the If operator.

A common early stumble is forgetting to allow for no arguments at all. Reaching straight for args(0) is an error when none were passed, so check args.Length first.

In professional work, command-line arguments are used in batch jobs and tools that need a different setting or file path on each run.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)