Skip to content

Classes & Objects

CrossBasic brings full object-oriented support to XojoScript-style code. Use Class / End Class to group data (fields) and behavior (methods) into a single type.

Declaring a Class

Class Pair
  Dim LeftValue  As Variant
  Dim RightValue As Variant

  Sub Constructor()
    // default
  End Sub

  Sub Constructor(leftValue As Variant, rightValue As Variant)
    Self.LeftValue  = leftValue
    Self.RightValue = rightValue
  End Sub
End Class

Here we define a simple Pair class with two fields and two overloaded constructors .

Creating Instances

Instantiate with New:

Var p1 As New Pair              // calls default constructor
Var p2 As New Pair("foo", "bar") // calls overloaded constructor

Once created, you can use p1 or p2 just like any other variable.

Built-In Classes

CrossBasic includes many built-ins (e.g. DateTime, BinaryInputStream, XWindow, etc.). They follow the same instantiation pattern:

Dim dt As New DateTime
dt.Initialize(2025, 3, 17, 20, 8, 27)