Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command line arguments
#1
Hi all,

I've checked the forum but was unable to find an appropriate answer:

I'm trying to create an .EXE file (Compiled with QuickBACIS 4.5) that accepts parameters from the command line.

Ex.

C:> MYQBPROG.EXE PARAM1 PRAM2...

Is it possible? I hope it is! but haven't find a word on that...

Wish you can help.

Thanks and cheers from the Canary Islands.

Reply
#2
I don't know if that is possible, but, there might be a way around it.  Would you please post a couple of examples of the parameters you would like to use?  That might open the way to an acceptable solution.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#3
QB stores the command line details in Command$ (http://qbasicnews.com/qboho/qckadvr.c$x.shtml), should have what you are looking for.
Reply
#4
Wildcard:  Your link gave me a "The webpage cannot be found" message Sad  Cany you check it out and post the basic information the OP needs?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#5
Fixed the link, the forum didn't like the dollar sign in the url.
Reply
#6
Thanks a lot for your quick replies.

I'll give a go to the "command$" solution wich looks to fit pretty well into my needs.

Best from The Canaries.

Reply
#7
Hi. I've written many programs that require command-line parameters.

What I usually do is:
cmd$ = command$

This gets the entire command-line string into the variable cmd$, or whatever string variable name you like.

Then, I parse the variable cmd$ for the parameters that I expect.
I generally use a lot of switches like "/CS" which could mean "case sensitive", or "/OP" which could mean "output to printer."

For required filenames, I use "/INFILE=xxxxx" where "/INFILE=" is for a required input file, and "xxxxx" is the fiename.

This parsing of the command-line string sounds difficult, but you will fine that it is rather simple.

Wildcard's method seems nice, but you still need to parse the list of parameters in the provided list. Plus, you need to have the CMD_EX.BAS program available. I couldn't find it.

Regards..... Moneo
Reply
#8
This should come with your QB4.5 download along with other examples:

Code:
' *** CMD_EX.BAS -- COMMAND$ function programming example
'
' Default variable type is integer in this module.
DEFINT A-Z

' Declare the Comline subprogram, as well as the number and type of its parameters.
DECLARE SUB Comline (N, A$(), Max)

DIM A$(1 TO 15)
' Get what was typed on the command line.
CALL Comline(N, A$(), 10)
' Print out each part of the command line.
PRINT "Number of arguments = "; N
PRINT "Arguments are: "
FOR I = 1 TO N: PRINT A$(I): NEXT I

' Subroutine to get command line and split into arguments.
' Parameters:  NumArgs : Number of command line args found.
'              Args$() : Array in which to return arguments.
'              MaxArgs : Maximum number of arguments array
'                        can return.

SUB Comline (NumArgs, Args$(), MaxArgs) STATIC
CONST TRUE = -1, FALSE = 0

   NumArgs = 0: In = FALSE
' Get the command line using the COMMAND$ function.
   Cl$ = COMMAND$
   L = LEN(Cl$)
' Go through the command line a character at a time.
   FOR I = 1 TO L
      C$ = MID$(Cl$, I, 1)
    'Test for character being a blank or a tab.
      IF (C$ <> " " AND C$ <> CHR$(9)) THEN   ' Neither blank nor tab.
         IF NOT In THEN   ' Test to see if you're already inside an argument.
         ' You've found the start of a new argument.
         ' Test for too many arguments.
            IF NumArgs = MaxArgs THEN EXIT FOR
            NumArgs = NumArgs + 1
            In = TRUE
         END IF
         Args$(NumArgs) = Args$(NumArgs) + C$ 'Add the character to the current argument.
      ELSE          ' Found a blank or a tab.   
         In = FALSE   'Set "Not in an argument" flag to FALSE.
      END IF
   NEXT I

END SUB

Look in a Folder named Adver_ex for the example programs!

Ted
Get my QB demonstrator here: http://dl.dropbox.com/u/8440706/Q-Basics.zip
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)