-
Notifications
You must be signed in to change notification settings - Fork 3
twinBASIC Compiler Constants
This is a guide to the built in compiler constants in twinBASIC. It includes the constants listed for VBA even if they're not defined, as an undefined compiler constant can always be used, but will be 0.
Purpose: Indicates a 16-bit Windows compatible platform.
Value: Always 0 (False); 16 bit Windows is not supported.
Purpose: Indicates a 32bit compatible Windows platform
Value: Always 1 (True) on supported Windows platforms, for both 32bit and 64bit.
Purpose: Indicates a 64bit Windows AMD64 platform.
Value: 0 (False) when the compiler is in 32bit mode, 1 (True) when in 64bit mode.
Purpose: Indicates compatibility with VBA6 syntax.
Value: Always 1 (True).
Purpose: Indicates compatibility with VBA7 syntax.
Value: Always 1 (True).
Purpose: Indicates running on a MacOS platform.
Value: Always 0 (False). Mac is not currently supported, although this will change in the future.
Purpose: Indicates compatibility with twinBASIC syntax.
Value: Always 1 (True).
Usage of these follows the standard syntax of using a hashtag before the standard If/Else/ElseIf conditionals. For example, to differentiate between 32bit and 64bit VBA vs 64bit twinBASIC,
#If VBA7 Then
'We're in either VBA7 or twinBASIC
#If Win64 Then
'We're in either 64bit VBA7 or 64bit twinBASIC
#If TWINBASIC Then
'We're in 64bit twinBASIC
#Else
'We're in 64bit VBA7
#End If
#Else
'We're in either 32bit VBA7 or 32bit twinBASIC
#If TWINBASIC Then
'We're in 32bit twinBASIC
#Else
'We're in 32bit VBA7
#End If
#End If
#Else
'We're in VB6 or VBA6. Win64 will always be False by default. TWINBASIC will always be False by default.
#End If
Or more simply, to determine whether to use PtrSafe then DeclareWide:
#If VBA7 Then
'PtrSafe declares
#If TWINBASIC Then
'DeclareWide declares, if desired
#End If
#Else
'Declares without PtrSafe
#If TWINBASIC Then
'DeclareWide declares, if desired
#End If
#End If
Important
Reminder: Compiler Constants are not Boolean values, so you shouuldn't use syntax like #If Not Win64 Then as the result may not be desired, for instance that example evaluates to True when you likely used it or force.
The tB editor has the helpful feature of showing you in real time which compiler constants are active. Code in #If blocks will appear grayed out if it will not execute under current settings.
For example, in 32bit mode:

Then switching to 64bit mode:

VB6, VBA, VBA6, and VBA7 are trademarks of the Microsoft Corporation.
MacOS is a trademark of Apple, Inc.