kids encyclopedia robot

FreeBASIC facts for kids

Kids Encyclopedia Facts
Quick facts for kids
FreeBASIC
Fblogo.gif
FreeBasic help.png
Paradigm Procedural, object-oriented
Designed by Andre Victor
Developer The FreeBASIC Development Team
First appeared 2004; 21 years ago (2004)
Stable release
1.10.1 / December 25, 2023; 20 months ago (2023-12-25)
Typing discipline Static
OS MS-DOS, FreeBSD, Linux, Microsoft Windows
License GNU GPLv2+, Standard libraries licensed under the GNU LGPLv2+
Influenced by
QuickBASIC, C

FreeBASIC is a special computer program that helps you create your own software! It's a free and open-source tool, which means anyone can use it and even help make it better. FreeBASIC is a compiler, which takes the code you write and turns it into a program your computer can understand and run.

This programming language is based on an older, well-known language called BASIC. FreeBASIC works on many different computer systems like Microsoft Windows, Linux, and FreeBSD. It's designed to be very similar to QuickBASIC, an older programming tool from Microsoft. This makes it easier for people who learned QuickBASIC to switch to FreeBASIC.

Unlike some other tools, FreeBASIC usually works from the command line, which is like typing commands into a text window. But you can also add other programs, called IDEs, to make it easier to write and test your code with a visual interface.

How FreeBASIC Works

FreeBASIC uses other tools, like GNU Binutils, to help turn your code into working applications. It can create programs that run in a text window (console applications) or programs with graphics and buttons (graphical user interface applications).

Connecting with Other Programs

One cool thing about FreeBASIC is that it can work with code written in other programming languages, like C. This means that if someone has already made a useful piece of code in C, you can often use it in your FreeBASIC program. This helps programmers reuse code and build new things faster.

FreeBASIC also lets you write very specific instructions for your computer using something called "inline assembly." It can handle "multi-threading," which means your program can do several tasks at the same time, making it more efficient.

Code Preparation

Before FreeBASIC turns your code into a program, it has a special step called "preprocessing." This is like a quick check and setup phase. It can include other files of code, or change parts of your code based on certain rules. This helps keep your code organized and flexible.

Writing Your Code

FreeBASIC tries to be very similar to QuickBASIC in how you write code. But it also has many new features that make it more modern. For example, it supports "objects," which are like building blocks for your programs. It also allows "operator overloading" and "function overloading," which means you can make commands do different things depending on what you're working with.

When you write code in FreeBASIC, each instruction usually goes on its own line. If an instruction is very long, you can break it up onto multiple lines using an underscore `_`. You can also put several short instructions on one line by separating them with a colon `:`.

You can add "comments" to your code to explain what it does. This is helpful for you and anyone else who reads your code later. You can use an apostrophe `'` for a single-line comment, or `/'` and `'/` to comment out a whole block of code. FreeBASIC doesn't care if you use capital letters or small letters when you write your code, which makes it easier to type.

Making Graphics with FreeBASIC

FreeBASIC has a built-in way to create graphics, just like QuickBASIC did. It uses a special graphics library called FBgfx. This library works on different computer systems, using OpenGL on Linux and DirectX on Windows. This means you can write graphics code once, and it will work on both systems! However, FBgfx doesn't use your computer's graphics card to speed things up.

If you're an advanced user, you can also use other graphics tools like OpenGL directly with FreeBASIC, without any problems.

Different Ways to Code

As FreeBASIC has grown, it has added new features that sometimes change how older code works. To make sure old programs still run, FreeBASIC offers different "dialects" or styles of the language:

  • The default dialect (`-lang fb`) uses all the newest features and doesn't allow very old ways of writing code.
  • The FB-lite dialect (`-lang fblite`) lets you use most new features, but also allows some older ways of coding, especially if you're not using "objects."
  • The QB dialect (`-lang qb`) tries to act exactly like QuickBASIC. Many old QuickBASIC programs can run in this dialect without needing any changes.

Simple Code Examples

Let's look at some simple examples of FreeBASIC code.

This is a classic program that just prints "Hello, World!" on the screen. It's very simple and similar to how it was done in QuickBASIC.

Print "Hello, World!"

sleep:end 'Comment, prevents the program window from closing instantly

FreeBASIC can also do more advanced things, like using "objects" to organize your code. Here's an example of creating a "Vector" object, which could represent a point in space.

Type Vector
    Private:
        x As Integer
        y As Integer
    Public:
        Declare Constructor (nX As Integer = 0, nY As Integer = 0)
        Declare Property getX As Integer
        Declare Property getY As Integer
End Type

Constructor Vector (nX As Integer, nY As Integer)
    x = nX
    y = nY
End Constructor

Property Vector.getX As Integer
    Return x
End Property

Property Vector.getY As Integer
    Return y
End Property
Dim As Vector Ptr player = New Vector()

*player = Type<Vector>(100, 100)
Print player->getX
Print player->getY

Delete player

Sleep 'Prevents the program window from closing instantly

Both simple and advanced examples show that FreeBASIC is a great tool for learning how to program, whether you're just starting or want to explore more complex ideas.

See also

Kids robot.svg In Spanish: FreeBASIC para niños

kids search engine
FreeBASIC Facts for Kids. Kiddle Encyclopedia.