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

    Adding parameters to my application

    How can I use parameters whith my application???
    like:
    C:\MYAPP.EXE /s /r /t /y /start /t:34
    etc.

    Add handle them in my program

    thanks
    web_mickey


  2. #2
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Adding parameters to my application

    check out the Command$ function, it returns the parameters and then you can do split(s,"/") or something to separate them

    ----------
    The @host is everywhere!
    ----------

  3. #3
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Adding parameters to my application

    You can use Command() to get the commandline string, and then split the parameters. Like this:

    =============
    Option Explicit

    Public Sub Main()

    Dim rv As String 'return value
    Dim i As Integer

    i = InStr(1, Command(), "/s", vbTextCompare)

    'Check if key exists
    If i > 0 Then
    'Do something to handle "/s"
    MsgBox "Found /s!"
    End If

    i = InStr(1, Command(), "/r", vbTextCompare)

    'Check if key exists
    If i > 0 Then
    'Do something to handle "/r"
    MsgBox "Found /r!"
    End If

    ''''''''''''
    'TO DO: Add any cases if you want
    '''''''''''

    i = InStr(1, Command(), "/t:", vbTextCompare)
    'Check if key exists
    If i > 0 Then

    'strip off the key name plus all key-value pairs that came before the target key
    'ie. get value of key + anything after it
    rv = Mid(Command(), i + Len("/t:"))

    'strip off next key
    i = InStr(rv, "/")
    If i > 0 Then
    rv = Left(rv, i)
    End If

    'Return the value
    rv = Trim(rv)
    If rv <> "" Then
    'TO DO: handle with the value ( for example: rv="34")
    MsgBox "Found /t! vale=" & rv
    Else
    rv = "Exists"
    End If 'Do something to handle "/r"
    End If

    End Sub

    ============

    HTH

    Regards,

    Michi

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Adding parameters to my application

    The previous two appends describe the Command$ statement to retrieve command line parameters.
    In order to simulate command line parameters at DESIGN time, go to Project/Project Properties. Select the MAKE tab and enter your parameters in the "Command Line Arguments:" box.
    When your program issues the Command$ statement, whatever you specify here will be presented.

    John G

  5. #5
    Join Date
    Aug 2001
    Posts
    6

    Re: Adding parameters to my application

    Thank you for your help !!!


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