Skip to content

Language‐Syntax‐Reference

Claus Valca edited this page Sep 29, 2026 · 1 revision

📖 VBX Language Syntax Reference

This guide covers all core syntax, data types, control flow, and procedural constructs supported in VBX v0.1.0.


1. Variables & Constants

Variables use dynamic type inference based on their initial assigned value.

' Variables (Dim)
Dim count = 10                  ' Inferred as integer (long long)
Dim price = 19.99               ' Inferred as floating point (double)
Dim title = "Visual Basic X"    ' Inferred as string (const char*)

' Variable Reassignment
count = count + 5

' Constants (Const - Cannot be reassigned)
Const MAX_USERS = 100
Const PI = 3.14159
Const APP_NAME = "MyProgram"

2. Fixed-Size 1D Arrays

Arrays are zero-indexed and fixed in size. Standard parentheses syntax arr(i) is the official convention.

' Declaration: Allocates 5 elements (0 to 4), initialized to zero
Dim scores(5)

' Assignment
scores(0) = 95
scores(1) = 87
scores(2) = 100

' Access
Print "First score: " & scores(0)
Dim total = scores(0) + scores(1)

3. Operators

  • Arithmetic: +, -, *, /, % (or Mod)
  • Comparison: == (or =), != (or <>), <, >, <=, >=
  • String Concatenation: & (automatically coerces numbers to strings) and +
Dim x = 10 Mod 3               ' Modulo operator
Dim isEven = (x % 2 == 0)
Dim greeting = "Score: " & 100  ' Coerces 100 to string

4. Control Flow

If ... ElseIf ... Else ... End If

Dim score = 85

If score >= 90 Then
    Print "Grade: A"
ElseIf score >= 80 Then
    Print "Grade: B"
ElseIf score >= 70 Then
    Print "Grade: C"
Else
    Print "Grade: F"
End If

For ... To ... Next

' Iteration from 1 to 5
For i = 1 To 5
    If i == 3 Then
        Exit For    ' Early loop break
    End If
    Print "Number: " & i
Next i

While ... Wend

Dim n = 5
While n > 0
    Print "Countdown: " & n
    n = n - 1
Wend

Do ... Loop Family

' Do While ... Loop
Dim x = 0
Do While x < 10
    x = x + 1
    If x == 7 Then Exit Do
Loop

' Do ... Loop While (Executes at least once)
Dim y = 1
Do
    Print "Executing: " & y
    y = y - 1
Loop While y > 0

Select Case ... End Select

Supports both numeric and string comparisons seamlessly!

Dim role = "Admin"

Select Case role
    Case "Root", "Admin"
        Print "Full system access granted."
    Case "Guest"
        Print "Limited read-only access."
    Case Else
        Print "Unknown role."
End Select

5. Subroutines & Functions

  • Sub: An execution procedure that does not return a value.
  • Function: A procedure that calculates and returns a value using Return.
' Subroutine definition
Sub DisplayHeader(appTitle)
    Print "==============================="
    Print "  " & UCase(appTitle)
    Print "==============================="
End Sub

' Function definition
Function Multiply(a, b)
    Return a * b
End Function

' Calling procedures (supports both space and parentheses syntax)
DisplayHeader "Inventory Manager"
DisplayHeader("Inventory Manager")

Dim result = Multiply(6, 7)
Print "Result: " & result

6. Standard Library Quick Reference

Function / Statement Description Example
Print expr Prints text to console output Print "Hello"
MsgBox msg [, title] Native OS alert dialog MsgBox "Saved!", "Success"
InputBox(prompt [, title]) Native OS input prompt Dim x = InputBox("Age?")
File.Write(path, content) Writes text to a file File.Write "log.txt", "data"
File.Read(path) Reads entire file to string Dim s = File.Read("log.txt")
Len(str) Length of string Dim l = Len("VBX")
Trim(str) Strips leading/trailing spaces Trim(" abc ")
UCase(str) / LCase(str) Upper/Lower case conversion UCase("hello")
Left(s, n) / Right(s, n) Substring from left/right Left("Code", 2)
Mid(s, start, len) Substring (1-based index) Mid("Hello", 2, 3)
InStr(str, target) Find substring index (1-based) InStr("abc", "b") -> 2
Replace(s, find, rep) Replace occurrences Replace("cat", "c", "b")
Val(str) Parse number from string Val("42") -> 42
Str(num) Convert number to string Str(100) -> "100"
Abs(n) Absolute value Abs(-5) -> 5
Sqr(n) Square root Sqr(16) -> 4.0
Rnd() Random float (0.0 to 1.0) Dim r = Rnd()