Solved

Additional starting parameters

Posted on 1999-01-11
5
144 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month5 days, 15 hours left to enroll

626 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