PureBasic Survival Guide II - Converts
PureBasic Survival Guide
a tutorial for using purebasic for windows 5.50

Part 0 - TOC
Part I - General
Part II - Converts
Part III - Primer I
Part IV - Primer II
Part V - Advanced
Part VI - 2D Graphics I
Part VII - 2D Graphics II
Part X - Assembly
Part XI - Debugger
Part XII - VirtualBox
Part XIII - Databases
Part XIV - Networking
Part XV - Regular Expressions
Part XVI - Application Data
Part XXVII - Irregular Expressions
Part XXIX - Projects

Part II - Converts
v7.01 04.06.2017

2.1 Converts
2.2 GfaBasic
2.3 PureBasic 4.00
2.4 PureBasic 4.30
2.5 PureBasic 4.40
2.6 PureBasic 4.50
2.7 PureBasic 4.60
2.8 PureBasic 5.11
2.9 PureBasic 5.20
2.10 PureBasic 5.50
2.x Uncovered

2.1 Converts

This page is dedicated to those coming from another dialect, or older version.

PureBasic freshmen may want to skip this page and continue with the primer!

2.2 GfaBasic converts

This part of the survival guide helps former GfaBasic users to get started with the Windows version of PureBasic.

Why? Because Gfa is no more. Why PureBasic? Because it somewhat resembles GfaBasic. Why convert? Because Gfa is no more, and 32 bit PureBasic makes life a lot easier than old 16 bit GfaBasic for Windows. Why not GfaBasic32? Because it is no more either (and I never liked it anyway).

Why this page? To save you time (and to spare you the troubles others went through).

First have a look at the previous page, if you haven't done so already. Then continue below, where you will find a number of samples and conversions. This is far from complete, more might be added later. Or not... eternally under construction :-)


Variable names follow standard conventions. Variable types are defined using a postfix, except for pointers.

' gfabasic

a% = 1
b! = FALSE
c$ = "test"
d% = v:c$  '  pointers are ints

; purebasic

a.l = 1
b.l = 0     ; there's no boolean, but 0 = false, <>0 = true
c$ = "test" ; or c.s = "test"
*d = @c$    ; pointers resemble integers with a different name

See also here.

Variable scope

Variables in GFA are by default global, in PureBasic they are by default local. See also here.


In PureBasic there is no difference between a function and a procedure. Any procedure can return a value. The type of variable returned is defined in the procedure declaration.

' gfabasic

procedure test1
  ' do nothing

function test2(a%,b%)
  local c%
  c% = a%+b%
  return c%

d% = @test2(1,2)

; purebasic

Procedure test1()
  ; do nothing

Procedure.l test2(a.l,b.l)
  c.l = a+b
  ProcedureReturn c

d.l = test2(1,2)

See also here.


Alphabetical list of GfaBasic vs. PureBasic equivalent or alternative keywords / functions.

' gfabasic ; purebasic
\ %
^ Pow()
++ +1
char{} PokeS()
do .. loop Repeat .. Forever
exist() FileSize()
function .. return .. endfunc Procedure .. ProcedureReturn .. Endprocedure
getprocaddress() GetFunction()
inkey$ Inkey()
input$(1) no equivalent
instr() FindString()
l: no equivalent
loadlibrary() OpenLibrary()
mod %
not Not
p:() CallFunctionFast()
print PrintN()
procedure .. return Procedure .. EndProcedure
rinstr() no equivalent (see x_rfindstring())
select .. case .. endselect Select .. Case .. Endselect
string$() Lset()
v: @


In 16 bit GfaBasic it is necessary to do type forcing / type conversion when making a DLL call. This is not necessary in PureBasic.

' gfabasic

ws_winsock_h& = LoadLibrary("WINSOCK.DLL")  '  load the DLL and get back the DLL handle
ws_wsastartup% = GetProcAddress(ws_winsock_h&,"WSAStartup")  '  find the address of the function


ws_retval& = P:(ws_wsastartup%)($101,L:V:ws_wsadata.)

; purebasic 4.30

ws_winsock_h.i = OpenLibrary(1,"WSOCK32.DLL")  ; load the DLL and get back the DLL handle
*ws_wsastartup = GetFunction(1,"WSAStartup")  ;  find the address of the function


ws_retval.i = CallFunctionFast(*ws_wsastartup,$101,@ws_wsadata)

See also here and here.

2.3 PureBasic 4.00

PureBasic 3.94 was a giant leap forward from older versions. Now v4.00 and all later versions go to infinity and beyond ;-) Yes, as usual they break older code (a PureBasic habit) but what you get in trade is soooo cool, you're definitely going to like it. Here I'll add a few of the more obvious changes...


Some functions have changed in naming or syntax to become more consistent, or have been slightly improved, or are simply outright new. First stuff that changed, by keyword...

3.94 4.xx
Inkey() only returns a single character
IsFunction() GetFunction()
Procedure() now supports default values and optional parameters
Protected, Shared, Global, Static now allows assignment of values to variables
ResizeWindow(), MoveWindow() now combined similar to ResizeGadget()
Select Case EndSelect Case now supports ranges
ReadByte(), ReadWord(), ReadString(), etc. specify file number: ReadByte(<nr>) etc.
UseFile() obsolete, file nr now specified in file commands
UseWindow() obsolete, window nr now specified in window commands
WindowWidth(), WindowHeight() WindowWidth(<nr>), WindowHeight(<nr>)

New features

arrays and lists have now 'scope' (local or global), are default local and can be used as procedure parameters
global variables and procedure parameters can now have the same names
automatic protection of global variables when used as procedure parameters
strings can now be of any size and may be of an unlimited length
UniCode support with a special new variable type .c (char, used for Unicode independency)
new string variant added: fixed length strings .s{<length>}
additional types 64 bit .q and double float .d
Not is now! we finally got it... so is XOr by the way
Swap does what it says, it swaps two variables of the same type
With / EndWith makes filling structures easier
prototypes and pseudotypes
and more... see the readme.txt file in the PureBasic folder, check the help file, and visit the forum!

2.4 PureBasic 4.30

A new version, and new updates! And, as usual, it breaks your existing code :-)

Biggest change is the support of the new integer variable type .i for 32 or 64 bit programs. Just like the size of 'char' .c depends on Unicode mode, so does the size of 'integer' .i depend on the platform the code will be run on. The same applies to pointers!

The x86 32 bits version and x64 64 bits version have two different install packages. You can write cross platform code, but you can't generate it on the same platform.

  • Use Linux to generate Linux programs.
  • Use Windows 32 bits to generate and test 32 bits programs.
  • Use Windows 64 bits to generate and test either 32 bits or 64 bits programs.
Obviously I missed most changes (hehe) but perhaps I'll run into them and mark them with a newer version of PureBasic...


Some functions have changed in naming or syntax to become more consistent, or have been slightly improved, or are simply outright new. First stuff that changed, by keyword...

4.20 4.30
CreateGadgetList() no longer in use, each OpenWindow() now creates its own gadgetlist, you can still use UseGadgetList()
Read you now specify the type of data to be read, as in Read.s Read.l etcetera
StrQ(), ValQ() ... are no longer needed (see the help file)
CountList() ListSize()
lists and arrays as procedure parameters now need additional keywords (not sure if it was 4.30 that changed this though... could be earlier)

New features.

.i is a new integer variable that is either 32 or 64 bits depending on the platform
DesktopX() and DesktopY() make multi monitor programming easier

2.5 PureBasic 4.40

Another version, another chance to break things :-)

Many new features showed up in 4.40. Some of the changes below might have been introduced in a previous version, in which case I simply missed them :-)


4.30 4.40
CallFunctionFast() CallFunctionFast() only accepts integers, preceed strings by the '@' character
FlipBuffer() the synchronization parameter has moved to OpenScreen()
DrawingMode() PureBasic now supports alpha channels
default library subsystem DirectX7 default library subsystem DirectX9


alphachannel support (when things get funny try 24 bit image depth for images and / or icons instead of 32)
new unsigned variable types .a and .u
hash tables aka maps (very cool feature!)
regular expressions
sqlite blobs

2.6 PureBasic 4.50

Shorter release cycle with perhaps fewer features but indeed some important ones! Many bugs seem to be squashed as well.

One of the important changes is the way lower depth images are now handled... all images are now 24 bits (without alpha channel) or 32 bits (with alpha channel), though you can still save them with a lower depth. Also pay attention to the improvements to the debugger...


4.40 4.50
multiple image depths (on Windows only) images are now either 24 or 32 bits!


multiple compilers selectable
purifier tool
improved debugger
data breakpoints

Obviously, and as usual... this doesn't mean there were no other changes, it just means I didn't spot them, used them, of bothered mentioning them :-)

2.7 PureBasic 4.60b1

This upcoming release mostly brings improvements on the 3D side, but there are some other additions and improvements as well.

2.8 PureBasic 5.11

I've skipped a few versions, and the list of changes is humongous! Check the 'history' section in the help file for an overview of all changes. Here are some that caught my attention:

IP v6
retrieve environmental information such as ComputerName()
line continuation aka multiline (yes!)
wordwrap in the editor gadget
open files in shared mode
new sounds commands like GetSoundPosition()
improved TypeOf()
updated SQLite and Ogre
better Mac support
many 3D commands
IDE: reformatting code and other improvements
form designer

2.9 PureBasic 5.20

And more changes, mostly related to audio, graphics and joystick. Especially the sprite stuff has been redone. Good stuff for those that want to build a game...

2.10 PureBasic 5.50

After a long time I'm working again on the survival guide. In the meantime, purebasic 5.50 arrived, and as usual it made some (many!) chances... As I've been paying little attention since 5.11 the list of changes since 5.11 would become rather large... I'll just settle for my major observations... Of course I might simply have overlooked any of these in earlier versions...

no more support for Ascii mode, we're Unicode only now
session history
Enumerate now supports 'names'


Get ready and start with Primer Part I! 

2.x Uncovered...

This little section is here for my own use, so I can see what I forgot, need to add, or just ignore... Move on, people, nothing to see here :-)

all sprite3d stuff
module support
runtime library ?
OpenScreen() flipmode and refreshrate
editorgadget wordwrap
multicharacter stringfield
a.point = b.point
cipher library
trim ltrim rtrim character
defined() ?
2d drawing modes imageoutput()
lineargradient() etc.
gradientcolor() etc.
RGBA() Alpha()
line continuation character _ ?
exist() ?
on x call y,y,y,y ?
sgn() ?
Mod ?
Div ?
monitor coordinates
toolbarheight() ?
statusbarheight() ?
check the readme.txt in the pb folder
network library
resize window / resize gadget etc. ?
import / importc / endimport
Defined() function
regular expressions
CopyList() CopyMap() CopyArray() FreeList() FreeMap() FreeArray()
PlaySound() volume support
SaveImage() depth parameter