Link to home
Start Free TrialLog in
Avatar of Steve Williams
Steve WilliamsFlag for United States of America

asked on

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

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.

User generated image
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.
SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve Williams

ASKER

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.