Libraries

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Libraries

Post by Sinuvoid »

How do I:

1.Create them

2. Use them

Ive looked at tutorials and they all seem to be saying different things :?
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

That's not an easy question to answer.

You should know that generally, libraries contain only functions (SUB and FUNCTION in QB). If you're building a library with QB itself, you would simply have a project that contains a bunch of SUBs and FUNCTIONs that you don't want to have to copy over and over again. :) You would use the "Make Library" menu option in the QB editor. It'll create the library and quicklibrary automatically for you.

To make a library in assembly is different. The same basic concepts apply though; you're making a collection of functions. The difference is that you have to keep track of certain registers manually, and you have to know how to use LIB and LINK from the command line. Of course, you'll also have to know how to code in assembly language. :D

To use a library in the IDE, all you do is invoke the /l switch with the name of the library. Say you have library "foo", you do this:

qb /l foo

and the IDE will load with your library ready to use. Having the LIB alone isn't enough for the IDE; you also have to have the QLB version, which is what you need LINK for...I don't remember exactly how to do it (it's been at least 4 years since I did it last!) but information on how to do it isn't hard to find. I believe the syntax is something like...

link /qu bcom45.lib mylib.lib

or something like that...meh...I forget. :D

Also, most people who make libraries also tend to link in qb.lib. Since QB can only load one library at a time, lib.exe can assembly multiple library modules together to form a single .lib file, which you can then LINK to a QLB.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

LOL I gotta say!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

UH, that doesnt help :? I meant't creating QB libraries and using them.

Heres my code if it helps...

Code: Select all

DECLARE SUB Popup (A AS INTEGER, B AS INTEGER, c AS INTEGER, d AS INTEGER, text AS STRING, x AS INTEGER, y AS INTEGER)
DECLARE SUB Textbox (A AS INTEGER, B AS INTEGER, c AS INTEGER, d AS INTEGER, text AS STRING, x AS INTEGER, y AS INTEGER)
DECLARE SUB Checkbox (A AS INTEGER, B AS INTEGER, c AS INTEGER, d AS INTEGER)
DECLARE SUB Backround (A AS INTEGER)
'**********************************************************************************************
'* This is Interface Library Created and Coded by Souylsin                                    *
'* Backround Command                                                                          *
'* x 1 TO 63 color of backround. 1 being black to 63 being white.                             *
'* Checkbox Command                                                                           *
'* x,x, top left corner  x, length x height                                                   *
'* Popup Command                                                                              *
'*  Stynax: a,b,c,d,"text",e,f                                                                *
'* a,b, top left corner  c, length d, height  "", text here e, x plane to put text f,         *
'* y plane to put text                                                                        *
'* Textbox Command                                                                            *
'* Same as Above                                                                              *
'**********************************************************************************************
'Testing area


'Backround Command
SUB Backround (A AS INTEGER)
PALETTE 1, A + (A * 256) + (A * 65536)
LINE (0, 0)-(320, 320), 1, BF
END SUB

'Checkbox Command
SUB Checkbox (A AS INTEGER, B AS INTEGER, c AS INTEGER, d AS INTEGER)
PALETTE 12, 0 + (0 * 256) + (0 * 65536)
LINE (A, B)-(c, d), 12, BF
PALETTE 11, 63 + (63 * 256) + (63 * 65536)
LINE (A, B)-(c, d), 11, B
PALETTE 10, 63 + (63 * 256) + (63 * 65536)
LINE (A + 10, B + 10)-(c - 10, d - 10), 10, B
END SUB

'Popup Command
SUB Popup (A AS INTEGER, B AS INTEGER, c AS INTEGER, d AS INTEGER, text AS STRING, x AS INTEGER, y AS INTEGER)
PALETTE 7, 63 + (63 * 256) + (63 * 65536)
LINE (A + 0, B + 0)-(c + 6, d + 5), 7, BF
PALETTE 9, 0 + (0 * 256) + (0 * 65536)
LINE (A, B)-(c, d), 9, BF
PALETTE 10, 63
LINE (A - 1, B - 1)-(c + 1, d + 1), 10, B
PALETTE 6, 63
LINE (A + 1, B + 1)-(c - 1, d - 1), 6, B
LOCATE x, y
PRINT text
END SUB

'Textbox Command
SUB Textbox (A AS INTEGER, B AS INTEGER, c AS INTEGER, d AS INTEGER, text AS STRING, x AS INTEGER, y AS INTEGER)
PALETTE 13, 0 + (0 * 256) + (0 * 65536)
LINE (A, B)-(c, d), 13, BF
PALETTE 11, 63 + (63 * 256) + (63 * 65536)
LINE (A, B)-(c, d), 11, B
END SUB

Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

You should be able to just "Make Library" on that code.

EDIT: In fact, I just tried it out and it built the library just fine. :D Now all you would have to do is create and '$INCLUDE a .bi for it that contains the DECLAREs, unless you want to put them at the top of the source code that's going to use the library. And again, don't forget the /l switch.
Last edited by Nodtveidt on Mon Dec 24, 2007 3:02 pm, edited 1 time in total.
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Um, can you explain the last bit just a bit more? Im still kinda stumped :?
Thanks anyways :D
Last edited by Sinuvoid on Mon Dec 24, 2007 3:04 pm, edited 1 time in total.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

You use its routines the same way you'd use any ordinary SUB or FUNCTION.
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Nodtveidt wrote:You should be able to just "Make Library" on that code.

Now all you would have to do is create and '$INCLUDE a .bi for it that contains the DECLAREs, unless you want to put them at the top of the source code that's going to use the library. And again, don't forget the /l switch.
Explain that more deeply please :)
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Okay, I'll try...

Alright, in the source for your library, the QB editor will, as with any other QB program, create the DECLAREs for each SUB or FUNCTION you make. What you do is copy these DECLARE lines to a new file with the .BI extension. Then, in the program you're going to make that uses the library, use something like

'$INCLUDE "mylib.bi"

at the top of your source code. That will include all of the declares for your library so the functions can be used.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

To create a BI file, open Notepad and copy your original module Text Declares there. Then Save As. Click the dropdown box listed as Text and select ALL files and add .BI

You can do the same thing for BAS files from text.

Make sure to save your modules as Text Readable by other programs when saving them. Otherwise you will get a very ugly looking text file that you cannot read or copy. I imagine you already know that.

Still King here!

Ted
Last edited by burger2227 on Tue Jan 08, 2008 4:00 pm, edited 1 time in total.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

K thanks Burger. btw, are you by any chance related to ted felix?
Dav
Coder
Posts: 14
Joined: Thu Jul 15, 2004 9:23 am
Contact:

Same here

Post by Dav »

Nodtveidt wrote: I don't remember exactly how to do it (it's been at least 4 years since I did it last!) but information on how to do it isn't hard to find. I believe the syntax is something like...

link /qu bcom45.lib mylib.lib

or something like that...meh...I forget. :D
Heh, I had forgotten how as well, so I looked at my old makeqlb.bat which contains:
LINK /Q %1.LIB, %1.QLB, NUL, BQLB45;

The old LIB knowledge slammed back into my head (I quess QB isn't hard to jump back into...).

So, to make a QLB from FUNPAK.LIB, we'd do a:
LINK /Q FUNPAK.LIB, FUNPAK.QLB, NUL, BQLB45;

The /Q switch says make a QLB. It can be placed at the end, just has to be before that semicolon. To make a map file, replace NUL
with its name, or leave the space blank and the name will be
FUNPAK.MAP.

- Dav
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Um still dont really get it on using the library :?
Post Reply