Solved

Program Line switch

Posted on 2001-06-08
4
167 Views
Last Modified: 2010-05-02
How would I pull a program line switch? For example in pkzip you use pkzip -o for overwrite how would i do that same sort of thing in my app?
0
Comment
Question by:damion69
  • 3
4 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6168726
here is some code from freevbcode.com

Public Function RtnGetCommandLine(ArgArray() As String) _
   As Integer

'Purpose: Save all command line arguments to an array and return
'         Number of command line arguments.  Assumes command line
'         arguments are delimited by one space or a tab
'
'Parameters:  ArgArray: Uninitialized String Array in which
'             Command Line Arguments will be saved
'
'Returns:     Number of Command Line Arguments
'
'Example:
'Dim sArray() As String
'Dim iCtr As Integer

'MsgBox RtnGetCommandLine(sArray) 'displays number of command
'                                 line arguments
'For iCtr = 0 To UBound(sArray)
 '   Debug.Print sArray(iCtr) 'Outputs each argument
'Next

'NOTE: As written, will not work if there are more than 10
'Command line arguments, but you can change this easily if
'necessary.
'************************************************************
   'Declare variables.
   Dim C As String
   Dim CmdLine As String
   Dim CmdLnLen As Integer
   Dim InArg As Boolean
   Dim I As Integer
   Dim NumArgs As Integer

   'Initialise variables
   ReDim ArgArray(10)
   NumArgs = 0
   InArg = False
   'Get command line arguments.
   CmdLine = Command()
   CmdLnLen = Len(CmdLine)
   'Go thru command line 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 = 10 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)
   RtnGetCommandLine = NumArgs

End Function

it was written by  Anantha PAdmanabhan
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6168730
once you have the arguments you can do different things in your program depending on what is passed in
0
 
LVL 3

Accepted Solution

by:
jrspano earned 200 total points
ID: 6168780
if you don't want them in an array you need to just use the command()

ex

sub main()

dim s as string
s = Command()

's has all command params


end sub

ex

myprog  -s -r

s has the string "-s -r"
you then do different things depending on what is in there.
0
 
LVL 2

Author Comment

by:damion69
ID: 6169075
Wow I really didnt realize it was that easy or i wouldnt have made it so many points. But thank you for the great code.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now