Command line parameters with a VB Win32 Console Application

Posted on 2011-05-11
Last Modified: 2012-06-22
I created a Win32 application and would like to pass parameters to it.  The Main() for a VB application doesn't look anything like .Net C++ Win32:

      Sub Main()

      End Sub

Open in new window

How should the Main() look to accept parameters?

Question by:John500
    LVL 39

    Accepted Solution


    Public Sub Main(ByVal sArgs() As String)
            'Note the declaration of the Sub Main line
            'It has the sArgs parameter.  This parameter is handled by
            'the system, and contains any command line arguments.

            If sArgs.Length = 0 Then                'If there are no arguments
                Console.WriteLine("Hello World! <-no arguments passed->") 'Just output Hello World
            Else                                    'We have some arguments            
                Dim i As Integer = 0

                While i < sArgs..Length             'So with each argument
                    Console.WriteLine("Hello " & sArgs(i) & "!") 'Print out each item
                    i = i + 1                       'Increment to the next argument
                End While

            End If

        End Sub

    Author Comment

    Ok great!

    It all happens so quick.  What should I put in there to make it wait for user input before shutting the window down?

    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    To make it pause at the end, add this right before the "End Sub":

        Console.WriteLine("Press Enter to Quit")

    Author Closing Comment


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 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

    17 Experts available now in Live!

    Get 1:1 Help Now