Saturday, April 16, 2011

freeBASIC tutorial #1

        Recently I have been writing code in fbide (freeBASIC ide). I have found almost no online tutorials so I will create one. You can download the freeBASIC compiler at freebasic.net downloads page. The version I am using has been outdated since 2006, it should say that in the description. The language syntax is extremely similar to QuickBASIC and shares some C++ syntax.

       The first program that programmers will write in a new language is "Hello World". In freeBASIC, to display hello world in a console window you write:

                           1.  print "Hello world"
                           2.  sleep

         To display text to a console window you use the "print" command which simply means display the text. If you were to run the program without using the sleep command the console window would open and exit faster than you could read.

          Something a little more advance but fun to try is this program.


                            1. 1
                            2. color (c)
                            3. print "Hello world"
                            4. sleep 300
                            5. c = c + 1
                            6. if multikey(&h01) then goto 2
                            7. goto 1
                            8. 2

          If you don't understand this code that's fine, I will explain it more next time. I will be writing these tutorials a couple times a week. If you want to know when they first come out you can subscribe!

1 comment:

  1. nobody use goto, its not fine.

    Better example
    code:
    Dim c As Integer

    Do
    Color (c)
    Print "Hello World!"
    Sleep 500
    c += 1
    Loop Until MultiKey(&h01)

    ReplyDelete