This is a very old article written by me (around 2001, I guess) and it is just here for record.

Welcome to my tutorial for QB LIBRARIES. This will give you a basic understading about the QBasic Libraries. Here it starts.

First, write a program which contains all the subroutines that you want in your lib. The program can also contain other code but that won’t matter. Now, when you are in QB IDE environment(from where you run your progs), then from the menus above select “Run” and from the menu that comes, select “Make Library”, here it will ask you for the name of the library you are making. Type any name (Note that the name you give to your library will be the libraries file name). When you press Enter key after typing the library name, QB will temporarily exit and make the lib for you. After that, you will find some more files in the directory. They are:

The QuickLibrary. This is the file used by QuickBasic when running the program. This file is necessary for the QB to use the Library. You have to start QB like this to use the library.
QB progname /L libname
The Library. This file will be used when you compile your QB program into an EXE. This is not necessary to run the program from QB but it is needed when compiling.
The object file. This file is of little use to you. You can always delete it. But, if you are curious to know why it was created it, then read on. This file contains the machine language translation of the library code. In the actual process of compiling, first this file is created, then the .LIB file and at last the .QLB file. You can use this .OBJ file for merging your library with other libs from QB and other languages. This file is always deleted at last of the compiling process. Till then, it is an absolute necessity.

After this, you can use this library in your programs. To include it in programs, you have to start QB with the /L option and the library name. For eg.

QB /L libname or

QB /Llibname or

QB myprog/Llibname

Got it?
In every program you make with the help of the lib. There should be the declarations for the subroutines and functions you want to use in your program from the library. For eg. if your library contains a sub named DrawLine, then in each program you should include this line.

DECLARE SUB DrawLine([argslist])

[argslist] has to be replaced with the arguments that have to be passed to the function. Suppose, the original function was defined with 5 integer arguments this way.

DrawLine x1%, y1%, x2%, y2%, colour%

Then your program should also contain the declaration with 5 integer arguments. If you do not do this, then the program crashes. For eg.

DECLARE SUB DrawLine(x1%, y1%, x2%, y2%, colour%)

should be in every program you write.

Actually, the name of the variables you use in your programs SUB declaration can be different from those defined in the original lib. For eg. this can be done.

DECLARE SUB DrawLine(startX%, startY%, endX%, endY%, linecolour%)

but the type of variables passed should be the same. You cannot use LONG integers where you were supposed to use INTEGERs. This also crashes the program.

For FUNCTIONs, you declare the same way except for one thing. You should also specify the type of value the function returns. For eg. if you have a function named Memory which returns the amount of memory available in INTEGER, then you should declare the function like this.


I hope you understood this part. If you haven’t read it again because if you don’t you will not understand the next section.

This section deals with changing the function and sub names in your program without changing the library. In the former example, DrawLine was used, we use it again here.

Suppose, you don’t like the name DrawLine or you want to make it shorthand DL for faster code writing. Then you specify in the declaration which name you want like this.

DECLARE SUB DL ALIAS "DrawLine" (x1%, y1%, x2%, y2%, colour%)

Here, the only new thing is the part DL ALIAS “DrawLine”. This tells that the procedure has the name “DrawLine” in the library but you want to use DL. Simple. Read it again if you didn’t get it.

That’s all till here. Next section deals with making .BI files for ease.

Till now you noticed that in all the programs you make, you have to put all the declarations again and again. Quite tedious, isn’t it?

Well, instead of doing all this. What you can do is take all the declarations from the lib and put it in a .BI file. A good name for a .BI file will always be the libraries name to which it is associated. For eg. if your libraries name is MyLib, then you can make the BI file with the name MyLib.BI. However, this is not necessary. You can give any name you want.

After this, you have to include the BI file in your program. Otherwise, your program won’t come to know of it. You have to use this line.


This tells QB, to get all the declarations from a file named MyLib.BI

That’s all for today. I hope you enjoyed reading this and gained useful knowledge.

Tagged with: