none
Command Line Arguments (VisualBasic) RRS feed

  • Question

  • Hello.
    I need to write an application that must take arguments from command line. I found a function on msdn.

     Function GetCommandLineArgs() As String()
    
      ' Declare variables.
    
      Dim separators As String = " "
    
      Dim commands As String = Microsoft.VisualBasic.Interaction.Command()
    
      Dim args() As String = commands.Split(separators.ToCharArray)
    
      Return args
    
     End Function
    
    

    But there is an error on this line

    Dim commands As String = Microsoft.VisualBasic.Interaction.Command()

    The error is saying: "NotSupportedException was unhandled" and the exception detail is

    System.NotSupportedException was unhandled
    
     Message="NotSupportedException"
    
     StackTrace:
    
      at Microsoft.VisualBasic.Interaction.Command() at Alarm.Form1.GetCommandLineArgs() at Alarm.Form1.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis) at System.Windows.Forms.Control.set_Visible(Boolean value) at System.Windows.Forms.Application.Run(Form fm) at Alarm.Form1.Main() 
    
     InnerException:
    
    
    I'm using Visual Studio 2008, .NET Framework 3.5 and Windows Mobile 5.0 Smartphone SDK. Can anyone help?
    Saturday, July 24, 2010 1:46 PM

Answers

  • You should be able to configure your project to use Main procedure (as oppose to a startup form) which receives arguments passed as parameter. Then you can store these and launch your main form using Application.Run()

    Module mainModule
      Function Main(ByVal cmdArgs() As String) As Integer
    

    See this for more.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by ctacke Sunday, July 25, 2010 4:08 AM
    • Marked as answer by imanligenc Sunday, July 25, 2010 8:05 AM
    Saturday, July 24, 2010 4:28 PM
    Moderator
  • Thanks...

    I've used this piece of code

     

    Module mainModule
      Sub Main(ByVal cmdArgs() As String)
        Dim returnValue As Integer = 0
        ' See if there are any arguments.
        If cmdArgs.Length > 0 Then
          For argNum As Integer = 0 To UBound(cmdArgs, 1)
            ' Insert code to examine cmdArgs(argNum) and take
            ' appropriate action based on its value.
          Next argNum
        End If
        Application.Run(Form1)
      End Sub
    End Module
    
    
    and selected the startup object to mainModule from the project properties.

     

    • Marked as answer by imanligenc Sunday, July 25, 2010 8:05 AM
    Sunday, July 25, 2010 8:02 AM

All replies

  • Microsoft.VisualBasic.Interaction.Command is not supported in the Compact Framework.

    I don't have an answer for you, though.  Perhaps you need to consider a design that doesn't attempt to use the command line?

     

    Dick


    Dick Grier. Author of Visual Basic Programmer's Guide to Serial Communications 4. See www.hardandsoftware.net.
    Saturday, July 24, 2010 4:18 PM
  • You should be able to configure your project to use Main procedure (as oppose to a startup form) which receives arguments passed as parameter. Then you can store these and launch your main form using Application.Run()

    Module mainModule
      Function Main(ByVal cmdArgs() As String) As Integer
    

    See this for more.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by ctacke Sunday, July 25, 2010 4:08 AM
    • Marked as answer by imanligenc Sunday, July 25, 2010 8:05 AM
    Saturday, July 24, 2010 4:28 PM
    Moderator
  • Thanks...

    I've used this piece of code

     

    Module mainModule
      Sub Main(ByVal cmdArgs() As String)
        Dim returnValue As Integer = 0
        ' See if there are any arguments.
        If cmdArgs.Length > 0 Then
          For argNum As Integer = 0 To UBound(cmdArgs, 1)
            ' Insert code to examine cmdArgs(argNum) and take
            ' appropriate action based on its value.
          Next argNum
        End If
        Application.Run(Form1)
      End Sub
    End Module
    
    
    and selected the startup object to mainModule from the project properties.

     

    • Marked as answer by imanligenc Sunday, July 25, 2010 8:05 AM
    Sunday, July 25, 2010 8:02 AM