Pages

2. Install FreeBASIC

My computer environment

My computer environment is pretty standard.  I have a Surface Pro 3 running Windows 10.  I prefer Chrome as a browser and try to use portable apps (http://portableapps.com/) where possible. When used with services like Google Drive, portable apps give you  a system that is easy to upgrade or replace.  Simply copy your portable applications onto your new computer and your good to go.

Compilers

Computers use machine code, written in binary (1's and 0's), to instruct the CPU what to do.  The sequences of 1's and 0's are difficult to work with so Assembly code has been created. The binary sequences are replaced by short mnemonics. Assembly code is easier for humans to read and write.  The Assembly code was put through an assembler to convert it into machine code so the computer could follow the instructions. Although easier to read, assembler instructions are so fundamental that it takes many assembler instructions to do anything useful.

Higher level languages such as Basic are easier again to read and can pack a lot of power in very little code.  Computers cannot understand high level languages and this is where compilers come in.  Compilers translate the high level language to machine code, that can be used by a computer.

Download FreeBASIC

The compiler we will use is FreeBASIC.  Head over to https://sourceforge.net/projects/fbc/files/ to find the compiler for your system.  I prefer not to install software on my computer so I will choose "Binaries - Windows".  This section holds compilers that you only need to copy to a directory; no installation is necessary.  Find the files with the zip extension.  If you have a 64 bit version of windows you can choose the ...win64.zip file, if you don't have a 64 bit version of Windows or are not sure, then choose the ...win32.zip file.  Your download should start within 5 seconds.

Sourceforge FreeBASIC download location

Windows specific downloads
Use the files that end in either -win32.zip or -win64.zip

Set up directory for FreeBASIC

Next up we need to set set up our computer for writing FreeBASIC programs.  I have a directory off the root of C:\ called Apps.  It's where I put all portable apps and  I have a shortcut to this folder on my desktop for easy access. I have created a new directory called Basic inside the Apps directory:  C:\Apps\Basic . You may wish to do the same.  The address bar looks like this:

Clicking on the address bar will give you C:\Apps\Basic


Leave this directory open and open another window that shows our downloads.  Double-click the downloaded FreeBASIC compiler file and Windows 10 inbuilt extraction tool will show the FreeBASIC-1.050.0-win32 (or win64  if you chose that) directory it contains inside it.  Now right-click on the directory and drag it to the newly created Basic directory.  My directory looks like this:
My directory with the 64 bit version of FreeBASIC

Renaming the FreeBASIC-1.050.0-win32 folder to FB will make working with the directory easier in the future, so let's go ahead and do that. If you double click the newly named FB directory you will find a number of subdirectories, a couple of text files, and a file called fbc.exe, you may not see the extension if you have extensions turned off in the view menu.  This last file is our FreeBASIC compiler.

Contents of FB directory
fbc.exe is the compiler

Testing our environment

Let's check that we have a working compiler. While in your Basic directory, right click and create a new Text Document and call it test.txt.  Make sure you have not selected a new Rich Text Document, this type of document contains lots of formatting instructions that will not be understood by the FreeBASIC compiler.  Open test.txt and enter the following text on the first line:
Print "Hello World"
Anything you need to type or will be output to the command prompt windows will be in a courier font in this blog; it helps make things easier to understand. Now save the file. Right click and rename the file to test.bas.  Basic programs use a .bas extension.

Now we have to get a command prompt to work inside the Basic directory that holds our compiler and our newly created basic script.  Open up a command prompt.  There are a number of ways to do this in Windows 10; you can:
  • enter 'command prompt' (without the quotes) in the search section of the taskbar;
  • press the windows key and x and select command prompt; or
  • press windows key and r and type cmd in the prompt.
You should end up with a window that looks something like this, your prompt will be different because it refers to your user name:
Command Prompt
At the prompt type:
cd c:\apps\basic\fb

When you press enter you will be taken to the directory you recently renamed and the command prompt will change display the new directory name.  At the prompt type:
fbc test.bas  
You are telling the basic compiler (fbc.exe - by the way, no need to type the .exe) to compile the script you wrote above. After a moment you will see a new file in your directory: test.exe.  If we try and run this from Windows Explorer you will see a screen flash on and then disappear - not very exciting.  Let's get back to the command prompt and type test.exe at the prompt.  Now you should get the following output:
Hello World
You have written your first program!! Give yourself a pat on the back and have a bit of a lie down. If you didn't get the expected result, go through the instructions again or leave a question below.  To finish off, you can delete both the test.bas and test.exe files, we won't need these.

I find the command prompt window text a bit too small to read comfortably.  While we have the command prompt open, firstly right click the title bar and select Properties. Select the Font tab and choose a bigger font size.  I find 16 works for me.  You can change other setting to suit you but I have left everything else alone.

Next Post

In the next post we will download an editor and rewrite our "Hello World" program again to make sure everything is set up correctly.  With the compiler set up as described above, and an editor configured by the end of the next post, we are ready to learn FreeBASIC and start programming.

Please feel free to leave a comment and see you in the next post.

No comments:

Post a Comment