Command Line Switches

 BBS: Inland Empire Archive
Date: 11-02-92 (19:00)             Number: 386
From: LUIS ESPINOZA                Refer#: NONE
  To: BOB LAPIERRE                  Recvd: NO  
Subj: Command Line Switches          Conf: (2) Quik_Bas
On (28 Oct 92) Bob Lapierre wrote to All...

 BL> I am trying to figure out, How can you make a Compiled QB4.5 program
 BL> recognize command line switches at the DOS prompt?  If anyone could
 BL> help
 BL> me out, I would greatly appreciate it.
 BL>
 BL>       Thanks,
 BL>
 BL>        Bob LaPierre

        Here is some code that I use:


SUB BreakCommand (cmd AS STRING, ar() AS STRING, Max)
  cnt = 0
  DO
    a = INSTR(cmd, " ")
    IF a = 0 THEN EXIT DO
    cnt = cnt + 1
    ar(cnt) = LEFT$(cmd, a - 1)
    cmd = MID$(cmd, a + 1)
  LOOP WHILE Max >= cnt
  IF cmd <> "" THEN cnt = cnt + 1: ar(cnt) = cmd
  FOR i = 1 TO cnt
    DO WHILE LEFT$(ar(i), 1) = " "
      ar(i) = MID$(ar(i), 2)
    LOOP
    DO WHILE RIGHT$(ar(i), 1) = " "
      ar(i) = LEFT$(ar(i), LEN(ar(i)) - 1)
    LOOP
  NEXT
  FOR i = 1 TO cnt
    IF ar(i) = "" THEN
      FOR j = i TO cnt - 1
        ar(j) = ar(j + 1)
      NEXT
      cnt = cnt - 1
    END IF
  NEXT
  Max = cnt
END SUB

And this is how to use it:

DECLARE SUB BreakCommand (Cmd AS STRING, ar() AS STRING, Max%)

  DIM ArgV(10) AS STRING

  Cmd$ = COMMAND$
  ArgC = 10
  BreakCommand Cmd$, ArgV(), ArgC

        Ok, things to note:
                ArgC is the amount of commands you want to retrieve
        from the command line (seperated by a space)
                The ArgV array will have all of those commands.
                Cmd$ is just a temporary variable to hold the COMMAND
                LINE...

                                        Luis




--- PPoint 1.33
 * Origin: The Rubber Room (1:207/213.5)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET