# twinBASIC Additions

twinBASIC extends the VBA language with new data types, language constructs, operators, runtime functions, and project-level capabilities. This page lists the additions that have a dedicated reference page, grouped by category.

For a broader overview aimed at developers coming from VBA or VB6, see the [welcome page](/index.md).

---

## New data types

| Type | Description | Notes |
|------|-------------|-------|
| **LongLong** | 8-byte signed integer | Available in both 32-bit and 64-bit builds; VBA restricts it to 64-bit |
| **LongPtr** | Pointer-width signed integer | 4 bytes in 32-bit, 8 bytes in 64-bit; use in `Declare` statements |
| **Decimal** | 128-bit fixed-decimal type | Available as a standalone declared type, not only as a **Variant** subtype |

See [Data Types](/Reference/Data-Types.md) for the full type table, and [Features → New Data Types](/Features/Language/Data-Types.md) for more detail on these three.

---

## New language constructs

### Object-oriented

- [**Interface**](/tB/Core/Interface.md) -- defines a COM interface using twinBASIC syntax; a class that **Implements** it must provide all members
- [**CoClass**](/tB/Core/CoClass.md) -- declares a COM co-class; generates COM registration metadata at compile time
- [**Inherits**](/tB/Core/Implements.md) -- makes one class inherit another's implementation (single inheritance only)
- [**Implements Via**](/tB/Core/Implements.md) -- an extended form of `Implements` that delegates interface dispatch to a member object instead of requiring per-member forwarding code
- [**Protected**](/tB/Core/Protected.md) -- declares a class member accessible to the class and its derived classes; VBA has no equivalent

### Generics

twinBASIC supports generic types and generic modules using the `Of` keyword. A generic class or module takes one or more type parameters at instantiation time --- for example, `EventLog(Of EventIds, Categories)` in the [WinEventLogLib](/tB/Packages/WinEventLogLib/EventLog.md) package, or `ServiceCreator(Of T)` in [WinServicesLib](/tB/Packages/WinServicesLib/ServiceCreator.md).

### New declaration keywords

- [**Delegate**](/tB/Core/Delegate.md) -- declares a typed function-pointer type; enables type-safe `AddressOf` and callbacks in the CDecl, ThisCall and FastCall calling conventions
- **Enum** member ranges -- enum members can now reference other members by name rather than only literal integers

### Flow control

- [**Continue**](/tB/Core/Continue.md) -- skips to the next iteration of the enclosing loop (`Continue For`, `Continue Do`, `Continue While`); VBA has no equivalent
- [**Return**](/tB/Core/Return.md) -- exits a **Function** or **Property Get** and supplies the return value in one statement; also retains the legacy **GoSub**/**Return** meaning

### Attributes

twinBASIC uses a square-bracket attribute syntax on declarations and modules:

```tb check_build projname=additions-attribute-syntax
[Description("Returns the absolute value of n.")]
[ConstantFoldable]
Public Function Abs(ByVal n As Double) As Double
    ' ...
End Function
```

See [Attributes](/tB/Core/Attributes.md) for the full list, including `[DllExport]`, `[DebugOnly]`, `[WindowsControl]`, `[MustBeQualified]`, `[PreserveSig]`, and more.

### Inline initialisation

Variables can be initialised at the point of declaration:

```tb check_build
Dim total As Long = 0
Dim greeting As String = "Hello"
Dim items() As String = Array("a", "b", "c")
```

See [Features → Inline Initialization](/Features/Language/Inline-Initialization.md).

### Parameterised New

`New` accepts constructor arguments when a class exposes a `Sub New` with matching parameters:

```tb check_build projname=parameterised-new
' [COMCreatable(False)] because a class whose only constructor takes arguments
' cannot supply the parameterless one COM creation requires.
[COMCreatable(False)]
Class PipeClient
    Private m_PipeName As String

    Sub New(ByVal PipeName As String, ByVal Token As LongPtr)
        m_PipeName = PipeName
    End Sub
End Class
```

The arguments go on the **New** expression, which means the assignment form rather than `As New`:

```tb check_build projname=parameterised-new
Dim token As LongPtr
Dim conn As PipeClient
Set conn = New PipeClient("\\.\pipe\mypipe", token)
```

> [!NOTE]
> `Dim conn As New PipeClient("\\.\pipe\mypipe", token)` is a syntax error. `As New`
> declares a variable that constructs itself on first use and takes no arguments; a
> constructor call with arguments is an expression, so it needs `Set` (or an inline
> initialiser).

See [Features → Classes and Modules](/Features/Advanced/Classes-and-Modules.md).

---

## New operators

| Operator | Description |
|----------|-------------|
| [**AndAlso**](/tB/Core/AndAlso.md) | Short-circuit logical AND --- the right operand is not evaluated if the left is `False` |
| [**OrElse**](/tB/Core/OrElse.md) | Short-circuit logical OR --- the right operand is not evaluated if the left is `True` |
| [**IsNot**](/tB/Core/IsNot.md) | Logical inverse of `Is`; `a IsNot b` is equivalent to `Not (a Is b)` |
| [**LeftShift**](/tB/Core/LeftShift.md) | Bitwise left shift; `x LeftShift n` shifts x left by n bits |
| [**RightShift**](/tB/Core/RightShift.md) | Bitwise right shift; `x RightShift n` shifts x right by n bits |

---

## New runtime functions

These functions exist in the VBA package but have no equivalent in standard VBA --- they are twinBASIC additions:

| Function | Module | Description |
|----------|--------|-------------|
| [**CType**](/tB/Modules/Conversion/CType.md) | Conversion | Explicit cast to a caller-supplied type; syntax `CType(expr, TypeName)` |
| [**If**](/tB/Modules/Interaction/If.md) | Interaction | Ternary --- evaluates to one of two values; only the chosen branch is evaluated |
| [**CallByDispId**](/tB/Modules/Interaction/CallByDispId.md) | Interaction | Invokes a method or property by its IDispatch dispatch ID |
| [**RaiseEventByName**](/tB/Modules/Interaction/RaiseEventByName.md) | Interaction | Raises an event by name, passing arguments as a **Variant** array |
| [**RaiseEventByName2**](/tB/Modules/Interaction/RaiseEventByName2.md) | Interaction | Raises an event by name with a variable-length argument list |
| [**ObjPtr**](/tB/Modules/Information/ObjPtr.md) | Information | Returns the COM-identity address of an object |
| [**VarPtr**](/tB/Modules/Information/VarPtr.md) | Information | Returns the address of a variable |
| [**StrPtr**](/tB/Modules/Information/StrPtr.md) | Information | Returns the address of a **String**'s underlying character buffer |
| [**IsArrayInitialized**](/tB/Modules/Information/IsArrayInitialized.md) | Information | Returns whether a dynamic array has been dimensioned |
| [**TranslateColor**](/tB/Modules/Information/TranslateColor.md) | Information | Translates an OLE colour to a plain RGB value |

Additional low-level memory, threading, and introspection functions are documented in the [HiddenModule](/tB/Modules/HiddenModule/index.md) section.

---

## Project and runtime capabilities

### 64-bit compilation

twinBASIC compiles to either 32-bit or 64-bit native code. The target is set per-project. See [Features → 64-bit Compilation](/Features/64bit.md) and use `#If Win64 Then` / `#If Win32 Then` to conditionally compile architecture-specific code.

### Static linking

The `Import Library` statement links compiled C code from `.obj`, `.lib` and `.a` files into the program, which calls its functions through `Declare` statements with no DLL beside it. The feature is experimental. See [Features → Static Linking](/Features/Advanced/Static-Linking.md).

### Fusion

A 64-bit program can host some 32-bit ActiveX controls, which run in a 32-bit helper process. See [Features → Fusion](/Features/Fusion.md).

### Multithreading

twinBASIC supports background threads through the `Thread` API. See [Features → Multithreading](/Features/Advanced/Multithreading.md).

### Inline assembly

The [**Emit**](/tB/Modules/HiddenModule/Emit.md) / [**EmitAny**](/tB/Modules/HiddenModule/EmitAny.md) functions inject raw byte sequences into the code generated for the enclosing procedure. The `[Naked]` attribute suppresses the generated prologue and epilogue. See [Features → Assembly](/Features/Advanced/Assembly.md).

### Enhanced API declarations

Beyond the standard `Declare`, twinBASIC adds:

- `DeclareWide` --- disables ANSI/Unicode conversion for string arguments
- `CDecl`, `ThisCall` and `FastCall` calling conventions on declares, procedures, delegates and interface members
- `ByVal` UDT passing
- Variadic (`CDecl` + `ParamArray ... As Any()`) parameter lists

See [Features → Enhanced API Declarations](/Features/Advanced/API-Declarations.md).

---

## IDE additions

- **CodeLens** --- inline action bars above procedures ("Run", "Debug", "Test") without leaving the editor. See [CodeLens](/tB/IDE/Code/IntelliSense.md#codelens).
- **Package server** (TWINSERV) --- install packages from a central registry without leaving the IDE. See [Features → Importing a package](/Features/Packages/Importing-TWINSERV.md).
- **Type inference** --- `Dim x = 1` infers **Long**; `For Each item In collection` infers the element type when the collection is typed. See [Features → Type Inference](/Features/Language/Type-Inference.md).
- **Conditional compilation constants** (`#Const`, `#If`) --- a superset of the VBA set; see [Compiler Constants](/Reference/Compiler-Constants.md).

---

### See Also

- [Data Types](/Reference/Data-Types.md) -- storage sizes and ranges for all intrinsic types
- [Features](/Features/index.md) -- in-depth coverage of every twinBASIC feature
- [Categories](/Reference/Categories.md) -- statements and procedures grouped by purpose
