Solved

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

Posted on 2016-09-07
3
70 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Assisted Solution

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

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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