Solved

Additional starting parameters

Posted on 1999-01-11
5
143 Views
Last Modified: 2010-05-03
How do I write code, so that I can identify additional starting parameters?

E.g.
If I, in Run, write: MyApp.EXE a_string -a -b -f:1000
Then when the app starts, I want to be able to write code that responds to the parameters
E.g. A messagebox that displays the "a_string" string, and so on...

Get the hint?

BTW: An example would be nice!
0
Comment
Question by:Olli083097
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
cognition earned 100 total points
ID: 1455448
Something like the following.

Dim sString as String
Dim nPos as integer
Dim Param()
Dim i as integer
Dim j as start
sString = Command
j = 1
While Instr(j, sString, "-") > 0 then
    i = Ubound(Param) + 1
    Redim Preserve Param(i)
    Param(i) = Mid(j, sString, nPos - j)
    j = i + 1
Wend

0
 
LVL 3

Expert Comment

by:cognition
ID: 1455449
' Takes a string and and gets the next word, and removes the word from the string
' If word to get then return the word after the comma - wordtoget comma
Public Function GetNextWord(sString As String, Optional sSeperator As String = ",", Optional WordToGet As Integer = 1) As String
Dim nPos As Long
If IsMissing(sSeperator) Then
    sSeperator = ","
End If
If Left(sString, 1) = sSeperator Then
    GetNextWord = ""
    sString = Mid(sString, 2)
Else
    nPos = InStr(1, sString, sSeperator)
    If nPos > 0 Then
       
        GetNextWord = Left(sString, nPos - 1)
        sString = Mid(sString, nPos + Len(sSeperator))
    Else
        GetNextWord = sString
        sString = ""
    End If
End If

GetNextWord = Trim(GetNextWord)
   
End Function

0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1455450
Use the Command$ internal variable to get the command line. For parsing, you can use this code:

'
'PURPOSE:   Splits a string to tokens
'ARGUMENTS:
'   IN szString:        the string to tokenise. Should be the string itself on the first call,
'                       and "" on the following calls.
'   IN szSeparators:    The characters that act as separators between the tokens in the
'                       string, can be more then 1 character
'RETURNS:   The next token in the string, or "" if nothing is left
'
'NOTES:     This uses static variable, hence only 1 string can be tokenised at one time.
'           Passing a string as the first parameter overrides previos calls, and the string
'           processing starts over. For more info, see help on 'strtok' in the C library reference
'
Public Function strtok(szString As String, szSeparators As String) As String
    Static szBuf As String  'Static buffer to store the string
    Dim I As Integer
    Dim iPos2 As Integer
    Static iPos As Integer
    Dim iTmp As Integer
    Dim iPos1 As Integer
    Dim bSet As Boolean
   
    If szString <> "" Then szBuf = szString     'Update to a new string
   
    If iPos = 0 Then iPos = 1
    iPos2 = iPos
    iTmp = Len(szSeparators)
       
    'Iterate through all the separators, and find the position of the closes next occurence
    'of any of them
    For I = 1 To iTmp
        iPos1 = InStr(iPos2 + 1, szBuf, Mid(szSeparators, I, 1))
        If iPos1 > 0 Then
            If Not bSet Then
                iPos = iPos1
               Else
                If iPos1 < iPos Then iPos = iPos1
            End If
            bSet = True
        End If
    Next I
   
    'If no more separators, means the string has ended, return all of it
    If Not bSet Then
        strtok = Right$(szBuf, Len(szBuf) - iPos)
        iPos = Len(szBuf)
        Exit Function
    End If
   
    If iPos2 = 1 Then
        strtok = Mid(szBuf, iPos2, iPos - iPos2)
      Else
        strtok = Mid(szBuf, iPos2 + 1, iPos - iPos2 - 1)
    End If
End Function

0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1455451
Hehe, I guess I was too slow :)
0
 

Author Comment

by:Olli083097
ID: 1455452
cognition: Thanx!

MikeP: hehe, jepp, too slow :-)

BTW: Here is what I used, it's from the VB help file:

Option Explicit

Private Sub Form_Load()
    Dim execCommand
    For Each execCommand In GetCommandLine
        If execCommand <> "" Then MsgBox execCommand
    Next
End Sub

Function GetCommandLine(Optional MaxArgs)
    'Declare variables.
    Dim C, CmdLine, CmdLnLen, InArg, i, NumArgs
    'See if MaxArgs was provided.
    If IsMissing(MaxArgs) Then MaxArgs = 10
    'Make array of the correct size.
    ReDim ArgArray(MaxArgs)
    NumArgs = 0: InArg = False
    'Get command line arguments.
    CmdLine = Command()
    CmdLnLen = Len(CmdLine)
    'Go thru command line one character
    'at a time.
    For i = 1 To CmdLnLen
        C = Mid(CmdLine, i, 1)
        'Test for space or tab.
        If (C <> " " And C <> vbTab) Then
            'Neither space nor tab.

            'Test if already in argument.
            If Not InArg Then
            'New argument begins.
            'Test for too many arguments.
                If NumArgs = MaxArgs Then Exit For
                NumArgs = NumArgs + 1
                InArg = True
            End If
            'Concatenate character to current argument.
            ArgArray(NumArgs) = ArgArray(NumArgs) & C
        Else
            'Found a space or tab.

            'Set InArg flag to False.
            InArg = False
        End If
    Next i
    'Resize array just enough to hold arguments.
    ReDim Preserve ArgArray(NumArgs)
    'Return Array in Function name.
    GetCommandLine = ArgArray()
End Function
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

710 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