This chapter lists the global statements and procedures that form the core of the twinBASIC language.
Warning
Work in Progress Below
Categorical List
Compiler Control
- Option - configure a compiler option
- #If … Then … Else - enable or disable compilation of enclosed code
- #Const - define a module-private conditional compiler constant
Declarations and Definitions
- Class, Module - define a class or module
- Interface, CoClass - (twinBASIC) define a COM interface or coclass using twinBASIC syntax
- Sub - define a procedure
- Function - define a function
- Property - define a property
- ParamArray - declare a procedure’s final parameter as a variadic argument list
- Enum - define an enumeration type with associated constants
- Type - declare a user-defined data type (UDT)/a structure
- Declare - declare an external/library procedure or function
- Event - declare an event
- Implements - specifies that a class implements a given interface
- End - terminate execution, finish a Function, Sub, Property, or Enum definition, finish a Type declaration; finish a Class or Module, finish an If, Select, or With block
Flow Control
Statements:
- Call - invokes a procedure or function
- Do … Loop, For … Next, For Each … Next, While … Wend - loops
- If … Then … Else - execute code conditionally
- Continue - skip to the next iteration of the loop
- Exit - exit a loop, procedure, function or property
- Return - return from a GoSub subroutine, or (twinBASIC) return a value and exit from a Function or Property Get
- Select Case - execute a code block selected by an expression
- With - bring a variable or expression into scope
- Goto, GoSub … Return - transfer execution to another location
- On … GoTo, On … GoSub - transfer execution to a location selected by an expression
- Stop - interrupt execution
Inline conditional functions — expression-level alternatives to the If…Then…Else and Select Case statements above:
- If - evaluate an expression and return one of two values; only the chosen branch is evaluated (twinBASIC addition)
- IIf - evaluate an expression and return one of two values; both branches are always evaluated
- Choose - return one value from a list, selected by 1-based index
- Switch - return the value paired with the first True condition in a list of (condition, value) pairs
See also:
- End - terminate execution.
- On Error, Resume - flow control for run-time errors (see Error Handling)
Error Handling
Statements:
- On Error - specifies what to do when an error occurs
- Resume - resumes execution after an error has been caught
- Error statement - simulates the occurrence of an error (legacy; prefer Err.Raise)
Procedures:
- Err - returns the ErrObject describing the current run-time error state
- Erl - returns the line number where the most recent run-time error occurred
- Error$, Error function - returns the error message that corresponds to a given error number
- CVErr - wraps a numeric expression in a Variant of subtype Error
- SetThreadGlobalErrorTrap - register a callback that fires when an unhandled run-time error escapes the active error handler chain on the calling thread
Variable Declaration
Statements:
- Dim - declare a typed scalar or array variable
- Const - declare a constant
- Public - declare a public variable in a class or module
- Private - declare a private variable in a class or module
- Protected - (twinBASIC) declare a class member accessible within the class and its derived classes
- Static - declare a a variable of static duration
Variable Assignment and Modification
Statements:
- Let - sets the value of a variable
- Set - changes the object referred by the variable
- New - create a new instance of a class
- LSet - assigns a user-defined type, or left-aligns a string
- RSet - right-aligns a string
Operators:
Arrays
Statements:
- ReDim - allocate or change the size of a dynamically-sized array
- Erase - fill a fixed-size array with default values, or invalidate a dynamic array
Procedures:
- LBound - smallest valid subscript for an array dimension
- UBound - largest valid subscript for an array dimension
- IsArray - returns whether a variable is an array
- IsArrayInitialized - returns whether an array has been dimensioned
See also:
- Dim - allocate a scalar or array variable
- Array, Filter, Join, Split - array helpers
- vbaAryMove, vbaRefVarAry - low-level Variant-array helpers (see Memory and Pointers)
File I/O
Statements:
- Open, Close - open/close a file for I/O operations
- Get, Put - read/write data from an open random access file
- Line Input, Print - read/write a line from/to an open text file
- Input, Write - read/write data from an open sequential access file
- Seek - change the current access position in an open file
- Lock, Unlock - lock/unlock a range of records in an open file
Procedures:
- Reset - close all open disk files
- Width - set the limit for line lengths when printing
- Input, Input$ - read a fixed number of characters from a sequential file
- InputB, InputB$ - read a fixed number of bytes from a sequential file
- ChDir, ChDrive - change the current working directory and disk drive
- MkDir, RmDir - create/remove a directory on disk
- Name - rename a file or directory on disk
- SetAttr - set attributes of a file on disk
- FileCopy - copy a file on disk
- Kill - delete a file from disk
- SavePicture - write a
PictureorImageto a disk file - MacID - convert a 4-character Mac file-type code (legacy)
State Management
Procedures:
- Load, Unload - load/unload a form or control into memory
- GetSetting, SaveSetting - retrieve/store a string value from/to the system registry
- GetAllSettings - retrieve every key/value pair in a section of an application’s registry entry
- DeleteSetting - remove value from the system registry
Events
Statements:
- RaiseEvent - raise an event that may be handled by event handlers
Procedures:
- RaiseEventByName - raise an event by name on an object, taking arguments as a Variant array
- RaiseEventByName2 - raise an event by name on an object, taking a variable-length argument list
- RuntimeCreateGetMessageHook - create an IGetMessageHook for filtering Windows messages destined for a window and (optionally) its descendants
See also
- Event - declare an event
- IGetMessageHook interface - subscribe a callback to a Windows message type, then start/stop delivery
User Dialogs
Procedures:
- MsgBox - display a modal message dialog and return the button the user clicked
- InputBox - prompt the user for a line of text and return what was entered
- Beep - sound a system beep
Process Control
Procedures:
- Shell - run another program asynchronously and return its task ID
- AppActivate - change the focus to, or activate, a named window
- SendKeys - send keystrokes to the active window
- DoEvents - yield control to the message loop so pending events can be processed
COM and Automation
Procedures:
- CreateObject - create a new instance of a COM/Automation object
- GetObject - obtain a reference to an Automation object loaded from a file or already running
- CallByName - invoke a method or property on an object dynamically by name
- CallByDispId - invoke a method or property on an object dynamically by IDispatch dispatch ID (twinBASIC addition)
- CreateGUID - generate a fresh GUID and return it as a registry-formatted string
- vbaCastObj - reinterpret an object as another COM interface (a typed
QueryInterface) - vbaObjSet, vbaObjSetAddref - assign a raw object pointer to an Object variable, with or without addref
- vbaObjAddref - increment the COM reference count of the object at a given address
See also:
- ObjPtr - return the COM-identity address of an object (see Memory and Pointers)
Command Line and Environment
Procedures:
- Command$, Command - return the command-line arguments passed to the program
- Environ$, Environ - return the value of a process environment variable
Colours
Procedures:
- RGB - build an RGB colour value from red, green, and blue components
- RGBA - build an RGBA colour value from red, green, blue, and alpha components
- RGB_R, RGB_G, RGB_B, RGBA_A - extract individual colour components
- QBColor - return the RGB colour value for a QuickBASIC colour index
- TranslateColor - translate an OLE colour value to a plain RGB colour value
Mathematics
Procedures:
- Atn, Cos, Sin, Tan - trigonometric functions
- Sqr - take a square root
- Exp - calculate an exponential with base $e$
- Log - calculate the natural (base $e$) logarithm of a number
- Sgn - return the sign of a number
- Abs - returns the absolute value of a number
- Round - round the number to a given number of decimal places
- Rnd - generate a random number in the range [0.0, 1.0)
- Randomize - seed the random number generator
- Partition - return a string label identifying which of a series of equal-width numeric ranges a value falls into (histogram-style bucketing)
See also:
- Fix, Int - extract the integer portion of a number
- CInt, CLng, CLngLng, CLngPtr - coerce to integer types (rounds half-to-even)
Type Conversion
Procedures that coerce an expression to a specific type:
- CBool, CByte, CCur, CDbl, CDec, CInt, CLng, CLngLng, CLngPtr, CSng - coerce to a specific numeric type
- CStr - coerce to String (locale-aware; preferred over Str)
- CVar - coerce to Variant
- CDate - coerce to Date; CVDate returns a Variant of subtype Date (legacy)
- CType - explicit cast operator with a caller-supplied target type (twinBASIC extension)
Procedures that convert between numbers and strings:
- Hex$, Hex - hexadecimal string representation of a number
- Oct$, Oct - octal string representation of a number
- Str$, Str - decimal string representation of a number
- Val - parse a string into a Double
- ValDec - parse a string into a Decimal
Procedures that extract the integer portion of a number:
Other:
- Nz - replace Null with a default value
See also:
- Format$, Format - locale-aware number formatting
- FormatNumber, FormatPercent, FormatCurrency, FormatDateTime - typed formatters
- CVErr, Error$, Error function - error helpers (see Error Handling)
Type Inspection
Procedures that name or identify a variable’s subtype:
- VarType - returns the VbVarType code identifying a variable’s subtype
- TypeName - returns the name of a variable’s data type as a String
Procedures that test a value’s state or subtype:
- IsDate - returns whether an expression can be evaluated as a date
- IsEmpty - returns whether a Variant is uninitialised
- IsError - returns whether an expression is an error subtype
- IsMissing - returns whether an optional argument was supplied
- IsNull - returns whether a variable contains a Null value
- IsNumeric - returns whether an expression can be evaluated as a number
- IsObject - returns whether a variable refers to an object
See also:
- IsArray, IsArrayInitialized - in Arrays
String Handling
Statements that modify strings:
Procedures that check properties of strings:
- Len, LenB - the length of a string
- Asc, AscB, AscW - returns the character code of the first letter in a string
- StrComp - compares two strings
- InStr$, InStrB, InStr - finds the position of a given substring in a string
Procedures that create strings:
- Chr$, Chr, ChrB$, ChrB, ChrW$, ChrW - returns the character having a given code
- Space$, Space - return a string of spaces
- String$, String - return a string of specified characters
Procedures that return modified strings:
- Left$, Left, LeftB$, LeftB - extract a left substring of a string
- Mid$, Mid, MidB$, MidB - extract a substring of a string
- Right$, Right, RightB$, RightB - extract a right substring of a string
- LTrim$, LTrim, RTrim$, RTrim - removes leading/trailing spaces from a string
- Trim$, Trim - removes leading and trailing spaces from a string
- StrReverse - reverses the order of characters of a string
- LCase$, LCase, UCase$, UCase - capitalizes or lowercases a string
- StrConv - converts the string to a specified format
- Join - concatenates a string array using a given delimiter
- Split - splits a string into a string array
- Replace - replaces substrings in a string
- Filter - filters a string array into a subset according to criteria
- InStrRev - returns the position of a given substring in a string, searching from the end
- Format$, Format - format a numeric expression in a specific way
- FormatNumber - formats an expression as a numeric string
- FormatPercent - formats an expression as a percent string
Procedures that convert between numbers and strings:
- CStr - coerce a value to String (locale-aware)
- Hex$, Hex - hexadecimal string representation of a number
- Oct$, Oct - octal string representation of a number
- Str$, Str - decimal string representation of a number
- Val - parse a string into a Double
- ValDec - parse a string into a Decimal
See also:
- FormatCurrency - format an expression as a currency string
- FormatDateTime - formats an expression as a date/time string
Date and Time
Procedures:
- Date, Time - set the current date and time
- FormatDateTime - formats an expression as a date/time string
- MonthName - returns the name of the specified month
- WeekdayName - returns the name of the specified day of the week
See also:
Introspection
Procedures:
- CurrentProjectName - returns the name of the current project
- CurrentComponentName - returns the name of the current component (module or class)
- CurrentComponentCLSID - returns the Class ID (CLSID) of the current class
- CurrentProcedureName - returns the name of the procedure in which the function is called
- CurrentSourceFile - returns the full path of the current source file
- ProcessorArchitecture - returns the processor architecture of the running application
- CompilerVersion - returns the twinBASIC compiler version number
- GetDeclaredTypeProgId, GetDeclaredTypeClsid, GetDeclaredTypeIid, GetDeclaredTypeEventIid - return the COM ProgID/CLSID/IID/event IID of a declared type, resolved at compile time
- GetDeclaredMinEnumValue, GetDeclaredMaxEnumValue - return the smallest/largest value of a declared enumeration, resolved at compile time
See also:
- IMEStatus - the current Input Method Editor mode (East Asian Windows only)
Memory and Pointers
Procedures:
- ObjPtr - return the COM-identity address of an object
- StrPtr - return the address of the underlying buffer of a String
- VarPtr - return the address of a variable
- AllocMem, FreeMem - allocate/release native memory blocks
- GetMem1, GetMem2, GetMem4, GetMem8, GetMemPtr - read N bytes from a memory address into a typed variable
- PutMem1, PutMem2, PutMem4, PutMem8, PutMemPtr - write a typed value of N bytes to a memory address
- vbaCopyBytes, vbaCopyBytesZero - copy a block of bytes; the Zero form clears the source after the copy
See also:
- vbaAryMove, vbaRefVarAry - low-level Variant-array helpers (see Arrays)
- vbaObjSet, vbaObjSetAddref, vbaObjAddref - object-pointer assignment and refcounting (see COM and Automation)
Threading and Atomics
Procedures:
- InterlockedExchangePointer - atomically exchange a pointer-sized value
- InterlockedCompareExchangePointer - atomically compare-and-swap a pointer-sized value
- InterlockedCompareExchange32, InterlockedCompareExchange64 - atomic 32-bit / 64-bit compare-and-swap
- InterlockedIncrement32, InterlockedDecrement32 - atomic 32-bit increment / decrement
See also:
- SetThreadGlobalErrorTrap - per-thread error trap (see Error Handling)
Inline Assembly and Codegen
Procedures:
- Emit - inject custom Byte values into the codegen of the enclosing procedure
- EmitAny - inject custom typed values into the codegen of the enclosing procedure (size inferred from each value’s data type)
- StackOffset - return the stack-frame offset of a variable, resolved at compile time
- StackArgsSize - return the total size of stack-passed arguments to the enclosing procedure
- UnprotectedAccess - return an object reference that bypasses access checks on private members
See also:
- Direct Assembly Insertion - the
Nakedmodifier and worked examples
Expression Evaluation
Procedures:
- Eval - compile and evaluate a twinBASIC expression supplied as a string
See also:
- ExpressionService module - the underlying engine, when more control over binders or compiled-expression reuse is needed
Financial
Procedures:
- DDB - depreciation of an asset via the Double-Declining Balance method
- FV - future value of an investment with constant deposits and interest
- Pmt - payment for a loan with constant payments and interest
- IPmt - interest payment for a loan with constant payments and interest
- PPmt - principal payment for a loan with constant payments and interest
- SYD - sum-of-years’ digits depreciation of an asset
- SLN - straight-line depreciation of an asset in one period
- PV - present value of investment
- IRR - internal rate of return for a series of cash flows
- MIRR - modified internal rate of return for a series of cash flow
- Rate - interest rate per period of an annuity
- NPV - net present value of an investment
- NPer - number of periods for an investment with constant deposits and interest
- FormatCurrency - format an expression as a currency string
Unit Testing
Modules of the Assert package:
- Exact - strictest comparison semantics; datatypes must match and no implicit conversions happen
- Strict - case-sensitive strings, otherwise standard twinBASIC equality
- Permissive - case-insensitive strings, otherwise standard twinBASIC equality
Each module exposes the same fifteen assertions: Succeed, Fail, Inconclusive, AreEqual / AreNotEqual, AreSame / AreNotSame, IsTrue / IsFalse, IsNothing / IsNotNothing, IsNull / IsNotNull, SequenceEquals / NotSequenceEquals. All are tagged [DebugOnly(True)] and compile out of release builds.
Deprecated
Statements:
- DefBool, DefByte, DefInt, DefLng, DefCur, DefSng, DefDbl, DefDec, DefDate, DefStr, DefObj, DefVar - used to give implicit types to single-letter variables