Learn XOJO with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
1
Xojo Counter and Theme Toggle
Dim count As Integer = 0
Dim isDark As Boolean = False
Sub updateUI()
System.DebugLog("Counter: " + count.ToString)
If isDark Then
System.DebugLog("Theme: Dark")
Else
System.DebugLog("Theme: Light")
End If
End Sub
Sub increment()
count = count + 1
updateUI
End Sub
Sub decrement()
count = count - 1
updateUI
End Sub
Sub reset()
count = 0
updateUI
End Sub
Sub toggleTheme()
isDark = Not isDark
updateUI
End Sub
' Simulate actions
updateUI
increment
increment
toggleTheme
decrement
reset
Demonstrates a simple counter with theme toggling using Xojo variables, methods, and event-driven style.
2
Xojo Fibonacci Sequence
Dim a As Integer = 0
Dim b As Integer = 1
System.DebugLog(a.ToString)
System.DebugLog(b.ToString)
For i As Integer = 1 To 8
Dim c As Integer = a + b
System.DebugLog(c.ToString)
a = b
b = c
Next
Generates the first 10 Fibonacci numbers and prints them.
3
Xojo Factorial Calculator
Function Fact(n As Integer) As Integer
If n = 0 Then
Return 1
Else
Return n * Fact(n - 1)
End If
End Function
System.DebugLog(Fact(5).ToString)
Calculates factorial of a number using recursion.
4
Xojo Prime Checker
Function IsPrime(n As Integer) As Boolean
If n < 2 Then Return False
For i As Integer = 2 To n - 1
If n Mod i = 0 Then Return False
Next
Return True
End Function
System.DebugLog(If(IsPrime(13), "Prime", "Not Prime"))
Checks if a number is prime.
5
Xojo Sum of Array
Dim nums() As Integer = Array(1,2,3,4,5)
Dim sum As Integer = 0
For Each n As Integer In nums
sum = sum + n
Next
System.DebugLog(sum.ToString)
Calculates sum of an array of numbers.
6
Xojo Reverse String
Dim s As String = "HELLO"
Dim r As String = StrReverse(s)
System.DebugLog(r)
Reverses a string.
7
Xojo Multiplication Table
Dim n As Integer = 5
For i As Integer = 1 To 10
System.DebugLog(Str(n) + " x " + Str(i) + " = " + Str(n*i))
Next
Prints multiplication table of a number.
8
Xojo Celsius to Fahrenheit
Dim c As Double = 25
Dim f As Double = (c * 9 / 5) + 32
System.DebugLog(f.ToString)
Converts Celsius to Fahrenheit.
9
Xojo Simple Alarm Simulation
Dim temp As Integer = 80
Dim thresh As Integer = 75
System.DebugLog(If(temp > thresh, "Alarm: Temperature Too High!", "Temperature Normal"))
Simulates an alarm if a threshold is exceeded.
10
Xojo Random Walk Simulation
Dim steps As Integer = 10
Dim pos As Integer = 0
For i As Integer = 1 To steps
If Rnd() < 0.5 Then
pos = pos + 1
Else
pos = pos - 1
End If
System.DebugLog(pos.ToString)
Next
Simulates a 1D random walk.