Solved

How to Add Command Line Aurguments to your VB.Net Code in Visual Basic Language

Posted on 2016-09-07
3
54 Views
Last Modified: 2016-09-07
I have looked on a few VB forums and Googled till my eyes started bleeding. There is almost no information or examples of how to add command line arguments to your project so you can run functions of a compiled .exe file. Here is some code I have been working on to add the arguments. Very simple functions are to hide the form and click button1 on load.

Private Sub frmForm1_Load(sender As Object, e As EventArgs) Handles Me.Load
        CommandLineArgs()
    End Sub

Public Function CommandLineArgs()
        Dim clArgs As String = Environment.CommandLine
        For Each s As String In clArgs
            Select Case s.ToLower
                Case "/r"
                    Button1.PerformClick()
                Case "/h"
                    Me.Visible = False
            End Select
        Next
        Return CommandLineArgs(clArgs)
    End Function

Open in new window


Here is a screenshot of the Project Properties window with the Command Line arguments. This does not help it function in debug mode.

Project Properties Window>Debug>Start Options>Command Line Arguments
Any help on this would be greatly appreciated. (My code doesn't work) If anyone knows the correct method for creating these switches please help me.
0
Comment
Question by:Steve Williams
3 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
ID: 41787968
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 41788004
Hi Steve;

Try the method like this. The command line args are available any time you need it via the Environment.CommandLine as a string or Environment.GetCommandLineArgs as an array. This line of code, Return CommandLineArgs(clArgs), is calling the method Recursively, I do not think this is what you wanted to do.
Public Sub CommandLineArgs()
    Dim clArgs As String() = Environment.GetCommandLineArgs
    For Each s As String In clArgs
        Select Case s.ToLower
            Case "/r"
                Button1.PerformClick()
            Case "/h"
                Me.Visible = False
            Case Else
                Console.WriteLine(s)
        End Select
    Next
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Steve Williams
ID: 41788050
Eric, your solution was way more than I needed. I'm sure for a huge application it would be justified but my application is just a simple tool that has less than 75 lines of code.

Fernando Soto's solution was quick and simple and it worked like a charm.

 I give Eric kudos for all the work he did on that article it was very nice and it has downloadable code which I'm going to put in my library for future use when and if I ever get that in depth in coding. I'm a Mechanical engineer by trade and only dabble in coding to support my Engineering requirements. I will say tho, coding is a lot of fun and I really enjoy the time I get to spend with it.

As always, you guys rock thanks again for your help.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.net and XML report from SCCM 5 20
Get Client IP on RDS - VB.NET 15 44
C# guarantee sql connection close 6 39
What namespace do I need to import? 2 26
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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