Solved

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

Posted on 2016-09-07
3
38 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 69

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now