Skip to content

Code Structure

CrossBasic uses block delimiters rather than braces to define scope. Proper organization and consistent indentation improve readability.

File Layout

A typical .xs file is structured as follows:

  1. Module & Class Definitions
  2. Global Variables & Constants
  3. Function & Subroutine Declarations
  4. Main Script Logic / Event Loop
' 1) Module Definition
Module AppConfig
  Public Const Version As String = "1.0"
End Module

' 2) Global Variables
Dim counter As Integer = 0

' 3) Subroutine & Function Declarations
Sub Initialize()
  counter = 0
End Sub

Function Increment(ByVal step As Integer) As Integer
  counter = counter + step
  Return counter
End Function

' 4) Main Script Execution
Initialize()
Print("Counter at start: " + Str(counter))

Dim newCount As Integer = Increment(5)
Print("Counter after increment: " + Str(newCount))

Block Delimiters

Block Type Opening Keyword Closing Keyword
Subroutine Sub Name(...) End Sub
Function Function Name() End Function
If Statement If ... Then End If
Select Case Select Case End Select
For Loop For ... To Next
While Loop While ... Wend
Do Loop Do / Do While / Do Until Loop

Indentation & Whitespace

  • Indent by two or four spaces (tabs are allowed but be consistent).
  • Indentation has no semantic effect—it’s purely for human readability.
If x > 0 Then
    Print("Positive")
ElseIf x < 0 Then
    Print("Negative")
Else
    Print("Zero")
End If

Case‑Insensitivity

  • Keywords, function names, and variable names are not case‑sensitive: Dim x As Integer, dim X as integer, and DIM x AS INTEGER are equivalent.