Qbasicnews.com
November 14, 2019, 09:34:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Command line arguments  (Read 7811 times)
Replycant
New Member

Posts: 2


« on: September 11, 2008, 12:01:22 AM »

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.

Logged
Ralph
Ancient Guru
****
Posts: 544


« Reply #1 on: September 11, 2008, 12:29:41 PM »

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.
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
wildcard
*.*
Administrator
__/--\__
*****
Posts: 2369



« Reply #2 on: September 11, 2008, 02:29:04 PM »

QB stores the command line details in Command$ (http://qbasicnews.com/qboho/qckadvr.c$x.shtml), should have what you are looking for.
« Last Edit: September 11, 2008, 05:16:16 PM by wildcard » Logged
Ralph
Ancient Guru
****
Posts: 544


« Reply #3 on: September 11, 2008, 04:18:20 PM »

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?
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
wildcard
*.*
Administrator
__/--\__
*****
Posts: 2369



« Reply #4 on: September 11, 2008, 05:17:12 PM »

Fixed the link, the forum didn't like the dollar sign in the url.
Logged
Replycant
New Member

Posts: 2


« Reply #5 on: September 11, 2008, 06:13:21 PM »

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.

Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #6 on: September 17, 2008, 08:37:35 PM »

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
« Last Edit: September 17, 2008, 08:52:31 PM by Moneo » Logged
Clippy
Member
*
Posts: 84



« Reply #7 on: October 16, 2008, 08:19:13 PM »

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
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!