Posts: 2
Threads: 1
Joined: Sep 2008
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.
Posts: 544
Threads: 27
Joined: Jan 2005
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.
Posts: 1,138
Threads: 211
Joined: Feb 2020
09-11-2008, 10:29 PM
(This post was last modified: 09-12-2008, 01:16 AM by wildcard.)
QB stores the command line details in Command$ (
http://qbasicnews.com/qboho/qckadvr.c$x.shtml), should have what you are looking for.
Posts: 544
Threads: 27
Joined: Jan 2005
Wildcard:Â Your link gave me a "The webpage cannot be found" message

 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.
Posts: 1,138
Threads: 211
Joined: Feb 2020
Fixed the link, the forum didn't like the dollar sign in the url.
Posts: 2
Threads: 1
Joined: Sep 2008
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.
Posts: 1,956
Threads: 65
Joined: Jun 2003
09-18-2008, 04:37 AM
(This post was last modified: 09-18-2008, 04:52 AM by Moneo.)
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
Posts: 82
Threads: 8
Joined: Jul 2008
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