Jump to content

Reading Command line arguments in VB.NET

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
I will show you how to make a program which reads the Command line arguments from a program, it's pretty easy if you know how to do it :)


First we declares a ReadOnlyCollection to store the value from our commandline.

        Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs


The to get them one by one it's just to refer to its index, in the example below a messagebox will pop up with the arguments one by one.


        For i As Integer = 0 To CommandLineArgs.Count - 1

            MessageBox.Show(CommandLineArgs(i))

        Next


This was actually all the code but before publishing you need to remember to uncheck the "use .deploy file extension" checkbox:



Posted Image


Posted Image


Now after publishing you will get the .exe file. If you create a shortcut to this .exe file you can add command line arguments to it as shown in the image below:

Posted Image


Our program can now read these argument and one messagebox showing "Argument1" will be shown and then one showing "Argument2".


That was it. Hope you liked it :D

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I like :) +rep
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very thorough! Nice work. +rep