CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2005
    Posts
    2

    Console application parameters

    hello,
    I have to make a .NET console application.

    I wrote this console application in a module but the problem is that I need to send to it 1 parameter.

    After declaring in:

    Public Sub Main(ByVal mtstr As String)
    'Code......
    end sub

    it's giving me an error "No accessible 'Main' method with an appropriate signature was found in 'IETextFileAssets'."

    if i remove the parameter declaration, no errors were captured.

    Can you please tell me how to send a parameter to a module in a console application ?
    A sample code will appreciated.

    Thanks in advance

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Console application parameters

    You can "Command" to retrieve the Command Line Parameters that you pass to your application.

    Code:
    Public Class Module1
    Shared Sub main()
    Debug.WriteLine(Command)
    End Sub
    End Class

    The above code will work, if you are just passing one parameter

    If you are passing more than one Command Line Parameter, then you need to split them into an array, somewhat like this..
    Code:
    Public Class Module1
    Shared Sub main()
    Dim arrCommand() As String
    'I Am assuming that parameters will be separated by a White Space
    'You can change that to any other character like "," or "|"
    arrCommand = Command.Split(" ")
    Dim sParam As String
    For Each sParam In arrCommand
    Debug.WriteLine(sParam)
    Next
    End Sub
    End Class
    



  3. #3
    Join Date
    May 2005
    Posts
    2

    Re: Console application parameters

    hi,
    It worked . 1000000 Thanks

  4. #4
    Join Date
    Sep 2002
    Location
    Israel
    Posts
    396

    Re: Console application parameters

    vb_the_best Hi.
    I try this but i get an error that says that says:

    'System.Windows.Forms.Command' is not accessible in this context because it is 'Private'.

    My startup object is not a form and it a Shared Sub main() sub in a public calss.

    can you help me?

  5. #5
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Console application parameters

    use
    Code:
    Microsoft.VisualBasic.Command
    instead of
    Code:
    Command

  6. #6
    Join Date
    Sep 2002
    Location
    Israel
    Posts
    396

    Re: Console application parameters

    Thanks it works good

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured