home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / pb / library6 / parsecmd.bas < prev    next >
BASIC Source File  |  1990-09-09  |  2KB  |  66 lines

  1. $IF 0
  2. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  3.  This code is based on an example from Henry Piper's (72330,1721)
  4.  posting in the Spectra area of the PCVenB forum on Compurserve of
  5.  September 6, 1990
  6.  
  7.  Made into a sub 9/9/90 by Barry Erick 75300,214
  8.  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  9.  
  10.  The code between the 'Here and 'ToHere should be included to use this.
  11.  Two variables result. NumArgs% returns the number of parameters on
  12.  the command line. The string array Args$() returns the actual arguments.
  13.  
  14.  Testing this demo can be done this way:  compile and run from
  15.   the command line as
  16.     ParseDemo First Second /another /stillanother andmore last
  17.  
  18.  The demo code will print the number of parameters and the actual
  19.  parameters.
  20.  
  21.  This can also be run from within the IDE my using Alt/O/P and entering
  22.  the parameters before running with F9
  23.  
  24.  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  25. $ENDIF
  26.  
  27.  DEFINT a-z
  28. 'Here
  29.  %False = 0
  30.  %True = -1
  31.  
  32. SUB ParseCmds
  33. SHARED Args$(),NumArgs%
  34. LOCAL Included%,StrLen%
  35.  NumArgs% = 0
  36.  Included% = %False
  37.  REDIM  Args$(25)
  38.  Cmd$ = COMMAND$
  39.  StrLen% = LEN(cmd$)
  40.  FOR I = 1 TO StrLen
  41.      Temp$ = MID$(Cmd$,i,1)
  42.      IF (Temp$ <> " " AND Temp$ <> CHR$(9) AND_
  43.          Temp$ <> "/" AND Temp$<>"-") THEN
  44.         IF NOT Included% THEN
  45.            NumArgs% = NumArgs% + 1
  46.            Included% = %True
  47.         END IF
  48.         Args$(NumArgs%) = Args$(NumArgs%) + Temp$
  49.      ELSE
  50.         Included% = %False
  51.      END IF
  52.  NEXT
  53. END SUB
  54. 'ToHere
  55.  
  56. ' Main Demo
  57.  CALL ParseCmds
  58.  
  59.  
  60.  
  61.  PRINT "There are";numargs; "commands on the command line"
  62.  FOR i = 1 TO numargs
  63.      PRINT "Argument number";i;" is:  ";args$(i)
  64.  NEXT
  65.  END
  66.