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:

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:

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:

  • Is - compares two object references for identity
  • IsNot - (twinBASIC) the logical inverse of Is

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:

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 Picture or Image to 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

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:

Command Line and Environment

Procedures:

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:

Type Conversion

Procedures that coerce an expression to a specific type:

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:

  • Fix - truncates toward zero
  • Int - rounds toward negative infinity

Other:

  • Nz - replace Null with a default value

See also:

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:

String Handling

Statements that modify strings:

  • Mid =, MidB = - assign to or replace characters or wide/narrow string sections

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:

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:

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:

  • CDate, CVDate - coerce an expression to Date or Variant (subtype Date)

Introspection

Procedures:

See also:

  • IMEStatus - the current Input Method Editor mode (East Asian Windows only)

Memory and Pointers

Procedures:

See also:

Threading and Atomics

Procedures:

See also:

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:

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: