General Syntax Rules

PureBasic has established rules which never change. These are:

Comments

Example

  If a = 10 ; This is a comment to indicate something.

Keywords

All keywords are used for general things inside PureBasic, like creating arrays (Dim) or lists (NewList), or controlling the program flow (If : Else : EndIf). They are not followed by the brackets '()', which are typically used for PureBasic functions.

Example

    If a = 1      ; If, Else and EndIf are keywords; while 'a = 1'
      ...         ; is a variable used inside an expression.
    Else
      ...
    EndIf
Keywords are regularly described in the chapters on the left side of the index page in the reference manual.

Functions

Every function must be followed by an opening round bracket '(' character, otherwise it will not be considered a function (this applies also to functions without parameters).

Example

    EventWindow() ; it is a function.
    EventWindow   ; it is a variable.
Functions are regularly included in the PureBasic "Command libraries", described on the right side of the index page in the reference manual.

Constants

All constants are preceded by the hash # character. They can only be declared once in the source and always keep their predefined values. (The compiler replaces all constant names with their corresponding values when compiling the executable.)

Example

  #Hello = 10 ; it is a constant.
  Hello  = 10 ; it is a variable.

Literal strings

Literal strings are declared using the " character. Escape sequences are supported by prepending the ~ character to the literal string. The supported escape sequences are:
  \a: alarm           Chr(7)
  \b: backspace       Chr(8)
  \f: formfeed        Chr(12)
  \n: newline         Chr(10)
  \r: carriage return Chr(13)
  \t: horizontal tab  Chr(9)
  \v: vertical tab    Chr(11)
  \": double quote    Chr(34)
  \\: backslash       Chr(92)
There are two special constants for strings:
  #Empty$: represents an empty string (exactly the same as "")
  #Null$ : represents an null string. This can be used for API
           functions requiring a null pointer to a string, or to really free a string.
Warning: On Windows, \t does not work with the graphical functions of the 2DDrawing and VectorDrawing libraries.

Example

  a$ =  "Hello world"  ; standard string
  b$ = ~"Escape\nMe !" ; string with escape sequences

Labels

All labels must be followed by a colon : character. Label names may not contain any operators (+,-,...) or special characters (,,,,...). Labels defined inside a procedure will be available only in that procedure.

Example

  I_am_a_label:

Modules

Modules use a :: (double colon) when referencing a module name. Be careful not to confuse these with the single colon used by labels.

Example

  Debug CarModule::NbCars

Expressions

An expression is something which can be evaluated. An expression can mix any variables, constants, or functions, of the same type. When using numbers in an expression, you can prefix them with the $ symbol to indicate a hexadecimal number, or with the % symbol to indicate a binary number. Without either of those, the number will be treated as decimal. Strings must be enclosed within straight double quotes.

Example

  a = a + 1 + (12 * 3)

  a = a + WindowHeight(#Window) + b/2 + #MyConstant

  If a <> 12 + 2
    b + 2 >= c + 3
  EndIf

  a$ = b$ + "this is a string value" + c$

  Foo = Foo + $69 / %1001  ; Hexadecimal and binary number usage

Concatenation of commands

Any number of commands can be added to the same line by using the : option.

Example

  If IsCrazy = 0 : MessageRequester("Info", "Not Crazy") : Else : MessageRequester("Info", "Crazy") : EndIf

Line continuation

Long expressions can be split across several lines. A split line has to end with one of the following operators: plus (+), comma (,), or (|), And, Or, Xor.

Example

  Text$ = "Very very very very long text" + #LF$ +
          "another long text" + #LF$ +
          " and the end of the long text"

  MessageRequester("Hello this is a very long title",
                   "And a very long message, so we can use the multiline" + #LF$ + Text$,
                   #PB_MessageRequester_Ok)

Typical words in this manual

Words used in this manual:
<variable> : a basic variable.
<expression> : an expression as explained above.
<constant> : a numeric constant.
<label> : a program label.
<type> : any type, (standard or structured).

Others

- In this guide, all topics are listed in alphabetical order to decrease any search time.

- Return values of commands are always Integer if no other type is specified in the Syntax line of the command description.
- In the PureBasic documentation, the terms "commands" and "functions" are used interchangeably, regardless of whether the function returns a value or not. To learn whether value is returned by a specific command or function, consult the description provided in the command's documentation.