twinBASIC Developer Preview 1 (v0.10.3423)

About

twinBASIC is a modern BASIC compiler that aims to be fully compatible with all existing VB6 and VBA code. This is a work in progress project. Features are being added and improvements are being made daily. For this initial preview we have disabled lots of upcoming features that are not yet ready for public exposure. There are also several parts of the VB syntax that are not yet supported. We are working hard behind the scenes to get the remaining parts of the syntax incorporated, so please bear with us.

This is a commercial project, but we are not asking for money at this stage. Additionally, the 32-bit Windows version of the project will be available completely free of charge. Developers that need to build 64-bit binaries will need to purchase a licence. Further details on this will be provided soon.

Disclaimer

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

Current Preview State

This preview version of twinBASIC can compile standalone EXE applications, as well as ActiveX DLLs that you can reference from other environments, like VBA.

Most of the common VB language features are complete, however there are several important things to note. These issues will be fixed in the weeks ahead.

  • Compiles only to 32-bit. We wanted to focus on key areas in this preview, without getting distracted by users hitting 64-bit compilation issues that are not specific to twinBASIC. Plus we have some 64-bit linker issues to work through.
  • Error numbers and descriptions don't always match VB yet
  • multi-threading only allowed via the debug console for now
  • vbWatchdog support disabled
  • Webserver extension library disabled
  • The VBA.Interaction.* namespace is implemented but has little test coverage, so there may be issues
  • The VBA.Strings.* namespace is implemented but has little test coverage, so there may be issues

Additionally, some language syntax is not yet supported, specifically:

  • all file operations; Open, Write, etc, and the FileSystem.* namespace
  • Legacy ‘GoSub’ syntax
Please review our 12-month ROADMAP for expected release dates of individual features.

Requirements

  • Install VS Code
  • Development environment currently tested and supported only on Windows 10

Getting Help

twinBASIC issue tracking is now live at github. We've been inundated with bug reports and feature requests from many different sources. Going forward, it would help immensely if you could report bugs and post feature requests over at the repository which will help us better keep track and manage requests.

twinBASIC - GitHub

twinBASIC - GitHub Issues

Alternatively, you can get in touch with the lead developer on twitter:

Installation

Watch our QUICK SETUP GUIDE:

Open VS Code and install the twinBASIC extension from the marketplace.

Getting Started - Sample 1 - HelloWorld!

Let’s dive in with a simple Hello World project.

Open VS Code, press F1 to open the command palette, and type 'twinBASIC: Create new project'

Select the 'Sample 1. HelloWorld' option

Next, choose a location to save the project. This will create two files for you, one with the file extension '.code-workspace', and another with the file extension '.twinproj'.

TIP: If you see a 'Restricted Mode' notice at the top of the VS Code window, click 'Manage' and then 'Trust'

If all went well, the newly created project should open and you'll be editing the HelloWorld.twin file:

To check everything is working, simply press the Build button on the twinBASIC panel.




If the message box didn’t appear, you might find that it is sitting behind the main VS Code window!

This is because the executable you just created runs in a separate process. We will have a fix for this before the final release of twinBASIC.



Let's have a look at the generated EXE file:

Don’t worry, your eyes are not deceiving you. The file size is correct! The HelloWorld project does compile to a very small EXE file. Also of note, it doesn’t need any runtime or redistributable components.


Congratulations. You just built your first twinBASIC executable!

TOP TIP:    The code-workspace file can be considered the twinBASIC solution file (potentially containing multiple projects). The twinproj file is the main project file, containing a virtual file system used by twinBASIC that further contains the source files used by your project. Currently, both files must be stored together in the same folder and named identically (except for the differing file extensions).

PREVIEW NOTE:    In a future revision we will offer automatic migration from VB6 project files (.vbp). We will also allow the project file to hold links to external files, as the files are currently stored directly into the twinproj filesystem. We already support VB6 .BAS and .CLS files that can be drag & dropped into a twinBASIC project.

Getting Started - Sample 2 - List network IP addresses

As seen in our preview video, this sample is a more complicated sample, containing some Windows API calls.

Open VS Code, press F1 to open the command palette, and type 'twinBASIC: Create new project'

Select the 'Sample 2. GetIPAddresses' option

Press the build button to generate the EXE and run it:

Getting Started - Sample 3 - A simple ActiveX DLL

Open VS Code, press F1 to open the command palette, and type 'twinBASIC: Create new project'

Select the 'Sample 3. MyCodeLibrary' option

When you build a project that is set to the build type of 'ActiveX DLL' in the project settings, twinBASIC creates a COM based DLL, exposing the public classes in your project to the outside world.

The generated DLL has an embedded type library, and this gets registered automatically during the build process, for the current user.

Once you've built the project, you can reference the DLL from any COM-compatible compiler, for example, VBA from within Access or Excel. Please note however, that because this preview only generates 32-bit binaries, you will need a 32-bit version of Access or Excel (or whatever host) to use it with.

Further instructions provided inside the project source file!

Getting Started - Sample 4 - A simple VBE COM AddIn DLL

Open VS Code, press F1 to open the command palette, and type 'twinBASIC: Create new project'

Select the 'Sample 4. MyVBEAddin' option

This example shows you how to create an Addin for the VBE. It demonstrates you how to implement the IDTExtensibility2 interface to consume the initial events provided by the VBE.

Press the 'Build' button on the twinBASIC pane to generate the DLL. You must now register the DLL as a VBE addin, by running the provided RegisterAddin32.reg file.

Please note however, that because this preview only generates 32-bit binaries, you will need a 32-bit version of Access/Excel/VB6 (or whatever host) to use it with.

Getting Started - Sample 5 - A simple COM AddIn DLL (for Excel / Access)

Open VS Code, press F1 to open the command palette, and type 'twinBASIC: Create new project'

Select the 'Sample 5. MyCOMAddin' option

This example shows you how to create an Addin for Office applications, like Excel or Access. It demonstrates how to implement the IDTExtensibility2 interface to consume the initial events provided by the host.

In addition, the sample creates a button on the Office Ribbon, by implementing the IRibbonExtensibility interface.

Press the 'Build' button on the twinBASIC pane to generate the DLL. You must now register the DLL as an Excel or Access addin, by running the appropriate RegisterAddin32.reg file.

Please note however, that because this preview only generates 32-bit binaries, you will need a 32-bit version of Access/Excel to use it with.

Starting a new twinBASIC project

Open VS Code, press F1 to open the command palette, and type 'twinBASIC: Create new project'

Select either 'Standard EXE' or 'ActiveX DLL'

Next, choose a location to save the project. This will create two files for you, one with the file extension '.code-workspace', and another with the file extension '.twinproj'.

To open the project later, you can open the code-workspace file with the File > 'Open Workspace...' menu option from within VS Code.

Build configuration settings

The build configuration settings allow for customizing the overall twinBASIC experience.

Project settings

The project settings allow for changing general project settings and COM references.

Multi-threading support

twinBASIC itself supports multi-threading, but before we unleash this feature properly to the world, we need to add some language syntax to support the feature.

In the meantime, you can test multi-threading capabilities from the debug console, by starting an expression with the tilde character (~) to indicate that you want to run the code on another thread.

Code-generation

Compiled code emitted by twinBASIC Preview 1 is unoptimized native code. Even though the output code is unoptimized, it is typically much faster than VBA (or VB6’s p-code compilation), simply due to it being native machine code.

Work is already underway to integrate LLVM into twinBASIC so that we can grab some of the amazing benefits it offers for code generation.

Generated EXE and DLL files tend to be very small with twinBASIC. Please note that generated EXEs and DLLs do not require any runtime or redistributable components! (unless you reference third-party components yourself).

New compiler features

We’ve already covered many of the new language features available in twinBASIC in our videos:



In case you missed them, let’s take a quick look at some of the new features available in twinBASIC...

Inline variable initialization

Return statement

DeclareWide syntax



The DeclareWide keyword turns off the implicit ANSI to Unicode conversions that usually happen behind the scenes when Strings are used with the Declare statement

Overloading

Parameterized Constructors



Naturally, since COM doesn't support parameterized constructors, only the default constructor is exposed via the generated COM type library.

Don't be alarmed... twinBASIC still supports Class_Initialize() too!

Generics



Oh, and generic inference is also supported, so you can simplify that...



Generics are supported for procedures, classes and UDTs. Generics are not exposed in the generated COM type libraries, and so can only be used internally via twinBASIC.

TOP TIP:    twinBASIC accepts literals as well as types in generic specifiers!

Implements per-procedure support

New datatypes



Block comments (as seen in many C style languages)

... and much, much more!! Check out our videos!

New operators

Bit shifting <<, >>

Assignment operators

Short-circuiting operators AndAlso, OrElse, If() operator

Special symbols for referring to the class/module name and procedure name: CurrentComponentName CurrentProcedureName


Visual Basic (VB) is a trademark of the Microsoft Corporation


Copyright © 2021 iTech Masters (VAT: GB202994606)