Command line parameters with a VB Win32 Console Application

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?

Who is Participating?
Kyle AbrahamsSenior .Net DeveloperCommented:

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
John500Author Commented:
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?

Mike TomlinsonMiddle School Assistant TeacherCommented:
To make it pause at the end, add this right before the "End Sub":

    Console.WriteLine("Press Enter to Quit")
John500Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.