FreeBASIC facts for kids
![]() |
|
![]() |
|
Paradigm | Procedural, object-oriented |
---|---|
Designed by | Andre Victor |
Developer | The FreeBASIC Development Team |
First appeared | 2004 |
Stable release |
1.10.1 / December 25, 2023
|
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 language and a tool called a compiler. It's free to use and change, which means it's open source. You can use FreeBASIC on many different computer systems, like Microsoft Windows, Linux, and FreeBSD. It's based on an older language called BASIC.
FreeBASIC helps you create different kinds of computer programs. You can make programs that run in a text window (like a command prompt) or programs with a graphical window that you can click on. It works a lot like QuickBASIC, which was a popular version of BASIC from Microsoft. However, FreeBASIC usually runs from the command line, so you type commands to use it. If you prefer, you can add a special program called an IDE to make it easier to write and test your code. Some popular IDEs for FreeBASIC are FBide, FbEdit, WinFBE Suite, and VisualFBEditor.
Contents
How FreeBASIC Works
FreeBASIC uses other tools to turn your code into a working program. It can create programs that work well with other software written in languages like C or even C++. This means that programs made with FreeBASIC can often be used alongside other programs.
FreeBASIC can also prepare your code in a special way. It can turn your FreeBASIC code into C code first. Then, that C code can be made even faster by another tool. This helps your programs run smoothly. FreeBASIC also lets you use very advanced coding tricks and handle many tasks at once within your program.
It has a "preprocessor" that helps get your code ready before it's turned into a program. This tool can do things like replace text or include other files in your project.
Writing Code in FreeBASIC
FreeBASIC started by trying to be very similar to Microsoft QuickBASIC. Over time, it has added many new features. This means FreeBASIC now combines old and new ways of coding. You can use modern features like objects, which help organize your code better. You can also make functions and operators work in different ways depending on what you need.
When you write code, each instruction usually goes on its own line. If an instruction is very long, you can break it into several lines using an underscore `_`. If you want to put many short instructions on one line, you can separate them with a colon `:`.
You can also add notes in your code called comments. These notes help you remember what your code does, but the computer ignores them. You can make a whole line a comment by starting it with an apostrophe `'`. For longer notes, you can start a block of comments with `/'` and end it with `'/'`. FreeBASIC doesn't care if you use uppercase or lowercase letters when you write code.
Making Graphics with FreeBASIC
FreeBASIC has a built-in way to create graphics, just like QuickBASIC did. This is done through something called FBgfx. When you tell your program to use graphics, FBgfx automatically helps. On Linux computers, it uses OpenGL for graphics. On Microsoft Windows computers, it uses DirectX. This makes it easy to write graphics code that works on different systems.
If you are an advanced programmer, you can also use other graphics tools like OpenGL or the Windows API directly. These can work alongside FreeBASIC's built-in graphics.
Different Ways to Code (Dialects)
As FreeBASIC has grown, some changes were made that affected older code. To make sure old programs still work, FreeBASIC offers different "dialects" or styles of the language:
- Default Dialect (-lang fb): This is the newest style. It supports all the modern features and doesn't allow very old ways of coding.
- FB-lite Dialect (-lang fblite): This style allows most new features, but also some older coding methods. It's a mix of old and new.
- QB Dialect (-lang qb): This style tries to act exactly like QuickBASIC. Many old QuickBASIC programs can run in this dialect without any changes.
Example Code
Simple programs, like the famous "Hello, World!" program, look just like they did in QuickBASIC.
Print "Hello, World!"
sleep:end 'Comment, prevents the program window from closing instantly
FreeBASIC also lets you write more advanced code using object-oriented programming. This includes things like methods (actions objects can do) and constructors (special functions that create objects).
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 code in FreeBASIC are good for learning how to program.
See also
In Spanish: FreeBASIC para niños