AllExperts > Qbasic, Quickbasic 
Search      
Qbasic, Quickbasic
Volunteer
Answers to thousands of questions
 Home · More Qbasic, Quickbasic Questions · Answer Library  · Encyclopedia ·
More Qbasic, Quickbasic Answers
Question Library

Ask a question about Qbasic, Quickbasic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Alex Barry
Expertise
I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, c/c++, python, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.

Experience
Hobby programming since 2000

I no longer belong to any community programming groups, but do have knowledge of *basic dialects and C/C++

 
   

You are here:  Experts > Computing/Technology > Basic > Qbasic, Quickbasic > Passing Parameters

Qbasic, Quickbasic - Passing Parameters


Expert: Alex Barry - 3/12/2009

Question
QUESTION: Hi Alex, i hope you can give me some idea regarding my problem. Can I pass a parameter coming from the outside of the program? For example I have a program named 'PROGRAM.BAS', can I pass a parameter on this by executing PROGRAM Jojo 1234? Wherein the Jojo and 1234 value will be accepted inside the PROGRAM.BAS and manipulated.

ANSWER: Hi, Jojo,

What you'll want is to use the COMMAND$() built-in array.  I'm not sure if this will work without compiling the program, though.
To call the script, you'd do something like:
qb.exe yourBasicCode.bas arg1 arg2 3

You'll have to play around with the command to get it working right.

You may want to make a command like this:

FUNCTION HasCommandLine( lookFor AS STRING, index AS INTEGER )
 DIM i AS INTEGER
 HasCommandLine = -1
 IF index < 0 THEN
   FOR i = LBOUND( COMMAND$ ) TO UBOUND( COMMAND$ )
     IF LCASE$( COMMAND$( i ) ) = LCASE$( lookFor ) THEN
       HasCommandLine = i
       EXIT FUNCTION
     END IF
   NEXT i
 ELSE
   IF LCASE$( COMMAND$( index ) ) = LCASE$( lookFor ) THEN
     HasCommandLine = index
     EXIT FUNCTION
   END IF
 END IF

END FUNCTION

I hope that helps you out,
-Alex

---------- FOLLOW-UP ----------

QUESTION: Thanks for the help on my first problem Alex. I hope you wouldn't mind if I ask a follow question. For example, I have a file SAMPLE.DAT, what command will I used to check if this file really exist before I use it? In CLIPPER or FOXPRO there is a File() function which check first the presence of the file by returning TRUE or FALSE. Is there an equivalent basic command for this? Thank you and more power.

Answer
Hi, Again,

QBasic doesn't have a built in function to see if a file exists.  There are a few "hacks" to look for a file, though.

FUNCTION FileExists( path AS STRING ) AS INTEGER
 FileExists = NOT 1
 SHELL "DIR /B " + path + " > tmp.txt"
 DIM f AS INTEGER
 f = FREEFILE
 OPEN "tmp.txt" FOR INPUT AS #f
   IF LOF( f ) THEN FileExists = 1
 CLOSE #f
 KILL "tmp.txt"
END FUNCTION

IF FileExists( "c:\randomfile.dat" ) THEN ...
IF NOT FileExists( "SAMPLE.DAT" ) THEN ...

That should work, if not, let me know, and I'll see what can be done,
-Alex

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.