twinBASIC Update: February 6, 2022

Highlights include the milestone release of WinForms functionality, control inheritance, ReadOnly class properties, and twinPACK updating documentation.

twinBASIC Update: February 6, 2022

On April 23, 2021, I helped Wayne Phillips introduce the world to twinBASIC at the Access DevCon Vienna conference.  I boldly predicted that twinBASIC (along with the Monaco editor) would replace VBA and its outdated development environment by 2025.  With that goal in mind, this weekly update is my attempt to keep the project fresh in the minds of the VBA development community.

Every Sunday, I will be providing updates on the status of the project, linking to new articles discussing twinBASIC, and generally trying to increase engagement with the project.  If you come across items that should be included here, tweet me @NoLongerSet or email me at mike at nolongerset dot com.

Here are some links to get involved with the project:


Highlights

Milestone Release:  WinForms Support!!!

Version 0.14.x released on Friday, with early WinForms support.  

Here's the announcement from Wayne:

As of v0.14.1, you can now create real Windows Forms with twinBASIC.  We're currently limited to the following controls:

• Label
• TextBox
• CommandButton
• OptionButton
• CheckBox
• ComboBox
• ListBox
• Timer
• HScrollBar
• VScrollBar

The controls are not 100% complete.  There are several gaps in the methods, events, etc, but on the whole you should find the the most common features are implemented.

Follow the announcement link above for a quick start guide, some limitations of the early release, and a running list of bug fixes and feature releases for the WinForms twinPACK package.

Windows Forms Controls Inheritance

You can now inherit base control functionality using the twinBASIC Implements ... Via  construct to create your own custom controls!

This would allow you to do things like create a standard "Date" textbox for handling all user date inputs or a "Money" textbox for handling currency inputs or even a "Scheduler" control to act as a custom Outlook-style calendar.

Pairing this new feature with the twinPACK package manager has the potential to be a game-changing combination.  I'm imagining both commercial and open-source projects that would build extended controls beyond the basic set included for VB6 compatibility.  

I'm not just talking about improved text boxes, but truly complex and innovative offerings à la DevExpress and Telerik (from the .NET world).  Or, to use an analogy from the VBx world, think ActiveX controls and OCX'es without all the deployment headaches.

Exciting times ahead!

ReadOnly Class Properties

As of version 0.14.1, you can now use the following syntax when declaring properties in twinBASIC classes:

Public ReadOnly FieldName
' --== AND ==-- '
Private ReadOnly FieldName

When you declare a class property to be ReadOnly, the compiler will not let you assign values to that property outside of the class constructor (i.e., Sub New()).

In other words, any values you wanted to assign to these properties would be based on the arguments you provide when constructing the class instance.  Once the object has been created, those values are locked in and can't be changed.

Around the Web

New Documentation for Updating Packages

With WinForms support provided via a twinBASIC package, it's important to know how to update packages in twinBASIC so that you can get the latest and greatest WinForms features.  Wayne created a wiki page with instructions: Updating a Package.

Basic overview of the process:

  1. Uncheck the twinBASIC package from references
  2. Confirm you want to delete the package from the filesystem
  3. Check the box next to the package in the [TwinPack Packages] list
  4. Save and close the settings file which will reload the compiler

The twinBASIC VSCode extension will NOT notify you of package updates yet, but that feature is planned and will be available soon.  The best way to track updates to the WinForms package is to subscribe to the following GitHub issue: Windows Forms GUI Support.

Calling All Designers

Over in the twinBASIC Discord server, Wayne Phillips put out a request for help designing icons for the form toolbox:

If we have any graphic designers in the house that would like to help out, please see if you can work your magic on a set of toolbox icons for the basic controls... it would be much appreciated!

Here's the current icon set:

And here are some early options to replace it.

Rob's Icon Set

These icons are inspired by the original VB6 icons, but redrawn to avoid running afoul of copyright issues:

nextKast's Icon Set

These icons are vector-based, so they scale better to multiple sizes:

New Submissions Welcome

If you have an eye for design, consider submitting your own icon set.  

As per Wayne's specifications,

Icons would ideally be 64x64 transparent PNGs.

Icon submissions have been done through the Discord server to this point.  If you don't have (or want to set up) a Discord account, you could also submit a design by opening a new case in GitHub.

Bizarre 32-Bit Project Naming Behavior

Finally, I have to post this because it bit me hard this week and the solution was not in any way what I expected.

I was converting a small script from VBScript to twinBASIC.  Everything was working great.  I compiled and ran a 64-bit version without any issues.  But when I compiled a 32-bit version, I was prompted for Admin approval every time I ran it.  To my great confusion, this behavior seemed to have something to do with the filename of the generated executable.

I assumed it must be some sort of strange twinBASIC bug, but no, it was Windows UAC being too clever by half (emphasis mine):

Installer Detection Technology
[Forces UAC elevation based on certain application characteristics.]

Installer Detection only applies to:
1. 32 bit executables
2. Applications without a requestedExecutionLevel
3. Interactive processes running as a Standard User with LUA enabled

Before a 32 bit process is created, the following attributes are checked to determine whether it is an installer:

Filename includes keywords like "install," "setup," "update," etc.
• Keywords in the following Versioning Resource fields: Vendor, Company Name, Product Name, File Description, Original Filename, Internal Name, and Export Name.
• Keywords in the side-by-side manifest embedded in the executable.
• Keywords in specific StringTable entries linked in the executable.
• Key attributes in the RC data linked in the executable.
• Targeted sequences of bytes within the executable.

That's right.  The reason Windows was prompting me for Admin credentials when running my application is because I had included the word "Update" in its name.  Microsoft obviously learned the error of their ways, as this monstrous policy decision does not affect 64-bit builds.

tl;dr: Don't include the words "install," "setup," or "update" in your twinBASIC application names.

Changelog

Here are the updates from the past week.  You can also find this information by installing the twinBASIC VS Code extension and clicking on the Changelog tab of the extension page:

[v0.14.7, 6th February 2022]

  • updated: Package Windows Forms Controls to v0.0.7
  • added: ControlTypeConstants.vbForm for use by the Windows Form Package

[v0.14.6, 6th February 2022]

[v0.14.5, 5th February 2022]

  • improved: Windows Forms Controls package v0.0.6 released now incorporating toolbox icons kindly provided by @nextKast (axisdj)

[v0.14.4, 5th February 2022]

  • improved: Windows Forms Controls package v0.0.5 released now includes Initialize events for all controls to help with control inheritance

[v0.14.3, 5th February 2022]

[v0.14.2, 5th February 2022]

[v0.14.1, 4th February 2022]

  • added: Sample 1a. HelloWorld (WinForms) example
  • added: Package: Windows Forms Controls, allowing creation of native Windows Forms from tB
  • added: VBA.Information.TranslateColor (OleTranslateColor equivalent) [ https://github.com/WaynePhillipsEA/twinbasic/issues/571 ]
  • added: extra argument to Serialize attribute to take a literal string as a friendly-name for serialization purposes
  • added: DefaultDesignerEvent attribute for indicating which event in a control is to be bound to when double-clicking the control in the designer
  • added: ReadyOnly modifier for class fields, syntax Public ReadOnly Field [ https://github.com/WaynePhillipsEA/twinbasic/issues/50 ]
  • fixed: Debug.Print with an expressoin containing a comma or tab could sometimes cause a crash in compiled files

All original code samples by Mike Wolfe are licensed under CC BY 4.0