QBXL Technical Articles

So you want to try out FreeBASIC, eh?

By SJ Zero

The future is upon us and you want to get started, don't you? Fear not! FreeBASIC is easier to get into today than ever before! Most problems with earlier versions which could have stood in the way of learning how to use FreeBASIC have been eliminated, and today, 99% of what you need to know to code in FreeBASIC is just old QuickBASIC material.

1. Getting started with the software

As of this writing, You can grab fbIDE bundled with FreeBASIC .12 right here. Install it like you'd install any windows program. This part is really easy. If you can't download a program and run an installer, you probably should look elsewhere -- like an etch-a-sketch -- for your programming needs.

2. Hello world!

Open up fbIDE and type the following:

PRINT "Hello World!"
SLEEP

Now press F5. Congratulations, you've just seen how much like QB FreeBASIC really is. Now you can use most console commands for QB just like you remember. for example:

LOCATE 10,10
PRINT "I'm the center of the universe!"
SLEEP


3. The amazing Screen 13
now, put "SCREEN 13" before your code, to see how easy it is to use graphics modes:
SCREEN 13
PRINT "Hello World!"
SLEEP

From there, all of the standard QB graphics commands work as you remember, as you can see in this example:

SCREEN 13
LINE (1,1)-(100,100),1,bf
PRINT "Hello World!"
CIRCLE (10,10),10,2
PSET (30,15),3

SLEEP

FreeBASIC also has new graphics features. For example, QB has never had a screen 14 or greater. Try running this program:

SCREEN 15
LINE (1,1)-(100,100),1,bf
PRINT "Hello World!"
CIRCLE (10,10),10,2
PSET (30,15),3

SLEEP

After opening a graphics window via the SCREEN command, you can also hit ALT-ENTER to change between windowed and fullscreen modes.

Another nice feature of the graphics library in FreeBASIC is that you can do page flipping in any video mode. The following code demonstrates this.

THERE IS NO EXIT IN THIS PROGRAM SO YOU MUST CLOSE THE CONSOLE WINDOW TO EXIT THE PROGRAM. THIS WILL WORK FOR ANY LOCKED UP OR UNEXITABLE FreeBASIC PROGRAM!

DIM page
DIM notpage
DIM a,b

screen 12, , 2 'This sets the screen for 2 pages
notpage = 1   'This sets the backpage

DO
   IF page = 0 THEN page = 1 ELSE page = 0   'These two lines flip the page and the
   IF notpage = 1 THEN notpage = 0 ELSE notpage = 1 'backpage
  
  SCREENSET page, notpage 'This flips the page
  
  CLS  'First we clear the screen
   b = b + 1
   IF b > 100 THEN b = 0
   FOR a = 1 TO 128
       PSET (b,a),a 'Then we draw a line. It moves without flickering.
   NEXT a
  
LOOP

This works for any mode, so you can use the high resolution modes for your programs with page flipping, using standard QB graphics commands!

4. Why ASM is probably pretty dead
I wouldn't be saying this if it wasn't true. Using ASM to increase the functionality of your program is dead. Ignoring SDL, Allegro, DirectX, OpenGL, et. al. for a minute, you've got the above page flipping and advanced graphics modes at your disposal, as well as inkey$, which we've all grown to love or hate, but there are also two new input commands which do things QBers have had to resort to assembly code to do since the dawn of time:

DIM x,y,buttons
CONST escapeKey = 1
SCREEN 12

WHILE NOT MULTIKEY(escapeKey) 'this checks the escape key every frame
  GETMOUSE x, y, , buttons 'This gets the mouse state
  PRINT x,y,buttons  
WEND

With this knowlege, you should be able to begin the transition to FreeBASIC, with all the perks that it entails; Speed, power, portability -- you're the man, cool guy!

--SJ Zero is the god of freebasic...no, no he isn't.