Microsoft QBasic
Click here for site map

Home
Intro
Lessons
Library
Reference
About
www.microsoft.com

This is a line. . .a short one

Tutorials

Tutorials

If you are at this page, we conviniently assume that you have downloaded the code, looked through it, and maybe even tried it out. We recommend it. If you have problems running it, send a email to us at lccorp1997@hotmail.com.


Your Lesson Starts Proper

The first thing you must have noticed about our program is that it must be in "c:\ultima8\" in order to work. Why is this so? Well, QBasic programs operate with a default directory in mind. This directory is by default the one in which the Qbasic.exe file is located in. If you use Open in your program without stating a direct path, QBasic will assume that the file is in the working directory. In our case, Ultima8 is our default directory. The default directory can be changed using the Chdir command. So, an alternative to using a direct path Chdir and forcing your user to put the program in a specified directory is to use variable subsitution.


SCREEN 12: COLOR 15: CLS
OPEN "setting.ini" FOR INPUT AS #1
INPUT #1, whether$: IF whether$ = "" THEN GOTO question
GOTO program

question:
INPUT "Enter the directory in which the program is located: "; locatedir$
CHDIR locatedir$
PRINT ""
INPUT "Do you wish to save this setting? (Y/N)"; savesetting$
IF UCASE(savesetting$) = "Y" THEN GOTO filesave
GOTO program

program:
' Program Code
SYSTEM

filesave:
OPEN "setting.ini" FOR OUTPUT AS #1: PRINT savesetting$, #1: CLOSE #1
PRINT ""
PRINT "Your settings have been saved!"
GOTO program

  • A program must have a Chdir to specify the default directory.

The next thing about a program is that you should make a setup program that will check whether the user has unzipped and setup your program successfully. This will help prevent complications later. A good way to do this is to make it a seperate program and use the Chain command to link them. Remember, QBasic has a built-in limit to how large your program can be. Keep that always in mind and use Chain to make chained programs, both to combat this and for easy file management and administrative purposes.

Notice that there are a few .bas files in the .zip and not just one.

  • Try to use chained files whenever possible. Also create setup programs.

Finally, we share with you a little tip on how to check whether files are there. Use the On Error command to specify a line label that will lead an error message stating the file is not there. Define the On Error just before your checking code. Then use Open to open each file you want to check and then Close it. If a file is not there the program will jump to the On Error label.

For example:

On Error GOTO nofile
OPEN "c:\autoexec.bat" FOR INPUT AS #1
CLOSE #1
PRINT "Your file is there!"
SYSTEM

nofile:
PRINT "We couldn't find your autoexec.bat file!"
SYSTEM

  • Check to make sure all files are there.

And finally, always specify an On Error label just in case something goes wrong.

On Error GOTO internalerror
PRINT "There was an abnormal internal error during program execution."
PRINT "Program will Terminate."
SYSTEM

  • Don't forget to include safety valves in your programs!

Well, that's all for your basics. Click below to go on!


Previous PageFillingNext Page

Home Intro Lessons Library Reference About

This is a line. -------- If you don't know what a line is, you're brain dead.

This is an imagemap menubar. Hey I think you know what an imagemap is.

[ Home ] [ Intro ] [ Lessons ] [ Library ] [ Reference ] [ About ]

This is a line. -------- If you don't know what a line is, you're brain dead.

This Webpage is ThinkQuest entry Unknown.
Email: lccorp1997@hotmail.com

This Webpage is Designed for Netscape Navigator 3.0 and MSIE 3.0
We prefer a 24-bit True Color mode with 640x480 screen mode.
This Webpage created for Thinkquest 1998.