Downloaded FreeBasic,double-clicked fbc.exe and nothing happened!!

Written by: Antoni Gual

The standard answer: "It's a command line app, just key in fbc your_source.bas" And it will not work unless you cd to the freebasic folder and have your bas file in it. If you try it and you end up with an .exe with the same name as your source, you did it! End or the article.

...ok, Pete, I'll write some more!

Windows has succeeded in making most of us some computer iliterates, so this tutorial will try to help Windows users to get started with FB. Linux and DOS users know better their command lines, so I won't adress them.

Fbc.exe is a console app: all the compilers you know work like this, only they come wrapped in a user-friendly IDE that hides the details from you. Freebasic was born 5 months ago,and their main developers concentrate in making the compiler faster, more stable and powerful.No official IDE exists yet, so you will have to live with some command line.

.

Starting with FreeBasic

First of all download the program at the official site http://www.freebasic.net. Make sure you grab the Windows version.

Create a folder c:\freebasic and unzip the distribution in it. It will create the bin, inc,lib and examples subfolders.

The trick of cd'ing to the freebasic folder and put the bas file on it is good for a test but you probably want to have your sources in their own folders, so you must modify your PATH to get everything working.

Setting the path

The PATH is the list of folders where a file is searched when no path is appended to the file name. The files are first searched in the work folder, then in the folders in the list.

A way to modify the PATH permanently is to modify your AUTOEXEC.BAT(W9x) or AUTOEXEC.NT(XP-2000) file, but if you (or program installers) do it for every app you will end having broken PATHS that don't fit in the environment and don't work correctly.

The solution is to use a wrapper batch file to modify the path, run the required app and set back the path to the original state. Moreover, it will allow us to drag-and-drop the source into it, and make all the dirty work.

Here are two batch files, one for W9x and another for XP-2000, as their commands are slightly different.

Batch for Windows 9x.

:: cfb.bat, wrapper for Freebasic Compiler set oldpath=%path% :: :: modify this line to suit your fb path :: set fbp=c:\freebasic path=%path%;%fbp%;%fbp%\bin;%fbp%\inc;%fbp%\lib %1 cd %1 fbc %1 if %errorcode%==1 pause path=%oldpath% set oldpath= set fbp=

Batch for Windows XP-2000.

:: cfb.bat, wrapper for Freebasic Compiler setlocal :: :: modify this line to suit your fb path :: set fbp=c:\freebasic path=%path%;%fbp%;%fbp%\bin;%fbp%\inc;%fbp%\lib cd /d %~dp1 fbc %~nx1 if %errorcode%=1 pause endlocal

Put the appropiate .bat file in your desktop and you will be able to drag and drop .bas files into it.

Testing the compiler

At last some action!!

Open Notepad and key in this first program. It has a deliberate error!

PRINT "Hello,World" DATE$ SLEEP

Save it as hello.bas, be sure of having cfb.bat the near it and drag-'n-drop the dource file to the bat.You will get:

C:\Program files\freeBASIC\examples\ dummies.bas dummies.bas(1) : error 3: Expected End-of-Line, found: 'date' Press any key to continue . . .

The second line is the important one. It says FB found an error in the line 1, someting is wrong before DATE$. If you know QB, you have already detected the problem. Put a semicolon before DATE$ and re-compile

This time the console window closes inmediately. This is because FB did'nt give any error mesage. In fact the compiler only created a hello.exe in the source folder. You can run it:

Hello World! It's 02-24-2005

Congratulations! you did it!

Testing the samples

You can compile and test the samples in the FB distribution.You should not have any problem with the compiler.

When running the samples some of them will trigger an error message about one dll file missing. This is normal,those programs use third party dll's that don't come with the distribution. The readme.txt file has the links to the sites distributing those libraries. You must download the proper .dll file and put it in your windows folder. The program should work fine then.

Compiling a QB program

Now you will likely want to recompile some of your QB code. It will not work correctly unless you do some changes .FB tries to avoid some of the weirdnesses of QB but it adds it's own, so you WILL have some errors. Don't try with a 2000 lines source!

The errors FB gives in simple programs come mainly from:

Difference
Workaround
The default variable type in FB is INTEGER while in QB is SINGLE. Add a DEFSNG A-Z to the top of your program.
FB does'nt allow two variables with the same name and a different suffix: A% can coexist with A$ in QB but not in FB. Also a variable can't have the same name as a keyword with a suffix added. FOR& is a valid name in QB, not in FB. You must rename all the offending variables.
To support ON ERROR and RESUME NEXT, the compiler must be called with fbc -xe yourcode.bas. Make a copy of the batch file and add -xe just after the call to fbc
CALL ABSOLUTE and CALL INTERRUPT are not supported. Avoid programs using them as they need adding substitute FB or 32 bit assembler routines.
The alignment and field sizes in a TYPE are different than QB Avoid programs using TYPE (UDT) variables to GET data from files, or learn how to modify TYPES.
Sound, printer and comm port are not implemented yet Avoid programs using them or check third party libraries
ON PLAY, ON KEY, ON COMM and writing/reading to hardware ports is not and will not be implemented Avoid programs using them or use Windows API workarounds
Slave Windows interface programs as DS4QB++ or DSOCK are not needed and will not work. Check third party libraries or the Windows API
QB librairies don't work The only usable libraries are those programmed in QB,not in assembler, provided you can have the source and re-compile them in FB.

An example of what can happen when re-compiling QB programs.

The code works correctly in QB and draws a Mandelbrot set

SCREEN 12 CONST module = 640& * 480 DO x& = (x& + 103) MOD module im = 0: re = 0 FOR iter% = 1 TO 255 im2 = im * im im = 2 * re * im + (CSNG(x& \ 640) / 200 - 1.2) re = re * re - im2 + (CSNG(x& MOD 640) / 240 - 1.9) IF (re * re + im * im) > 4 THEN EXIT FOR NEXT PSET (x& MOD 640, x& \ 640), iter% LOOP UNTIL x& = 0 DO: LOOP UNTIL LEN(INKEY$)

If you compile it with FB you will have no errors. Running it will give you the result on the left side. A weird Mandelbrot set.... Adding DEFSNG A-Z at the top will solve the problem: the result is the one in the right side

Where to go From here:

If you reached this point it means you patiented with my broken english, you liked FB and you want more..

Documentation: The FB documentation is a work in progress. The only correctly documented part is the graphics library made by Angelo Mottola, check gfxlib.txt in the distribution. For the rest, program as if you were using QB, and check the file keywords.txt if it don't works. If not, ask in QBasicNews, the developement forum. The sample code provided is a good source of information.

Get an IDE. VonGodric FBIDE made one specifically for FB. It will serve you until you start modularizing programs, as VonG's IDE is for a single document. There are general use IDEs you can adapt, and there are several FB-specific Ide's in developement, that will be available soon.

If you want to use SDL, FMOD, LUA, you should get the documentation for the third party libraries, at the same places where you got the dll's.

.

Get Docs for Libraries For doing a GUI application with menus, dialogs and toolboxes, you are alone with the Windows API. Some people is trying to port wxWidgets, it's a portable GUI library that works both in Windows and Linux.

Explore the Windows API jungle You will need a good documentation: The main reference youi can check online is the Microsoft Platform SDK. If you run Windows XP-2000 and you can make a 350 Mb download you can install it in your computer. You can too use the older (10 years) and smaller (8Mb) win32.zip Borland distributes with it's compilers. You can find it at ftp://ftp.borland.com/pub/delphi/techpubs/delphi2/win32.zip

Have Fun!