twinBASIC Update: August 5, 2024
Highlights include improved array features (better non-Variant support, compile-time type checking, and assignment syntax) and a command line arg handling discussion.
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 Monday week, 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, please leave a comment below.
Here are some links to get involved with the project:
- Custom twinBASIC IDE Installation Guide
- twinBASIC Discord Server (chat about the project)
- twinBASIC Wiki (list of new features not in VBx)
- GitHub Issue Tracker (report bugs)
- twinBASIC/VBx LinkedIn Group
Highlights
Arrays Get Supercharged
Back in April, FullValueRider requested some improvements to VB6's native array capabilities. In short:
- Improved support for typed arrays
- Less reliance on Variant when working with arrays
- Better compile-time type checking (follows from above)
- Easier and more readable array assignment
This past week, Wayne delivered:
This is now implemented in BETA 587. Array()
is now a generic intrinsic function. You can specify the subtype explicitly e.g. Array(Of Long)(1,2,3)
. When assigning to a variable, or when passing to a procedure parameter, the compiler can infer the subtype of the generic, so for example these are valid:
Dim myArrayOfLongs() As Long = Array(1,2,3)
myArrayOfLongs = Array(4,5,6)
Dim myFixedArrayOfLongs(0 To 2) As Long = Array(1,2,3)
myFixedArrayOfLongs = Array(4,5,6)
Debug.Print JoinLongs(Array(1,2,3))
Function JoinLongs(values() As Long) As String
Return Join(values, ",")
End Function
In the examples above, no Variant types are involved - the arrays are native longs.
If the subtype cannot be inferred by the compiler, and the subtype is not specified explicitly with (Of T)
, then the subtype will default to Variant
, like the standard VBx Array()
behaviour.
Note also that as of BETA 587, arrays can now be initialized on the Dim
line, as shown above.
Discord Chat Summary
* Auto-generated via Claude-3.5-Sonnet-200k on poe.com
Here's a summary of the key points from the twinBASIC Discord general channel transcript for the week of July 29 to August 5, 2024:
The twinBASIC community continues to make progress on various fronts, from fundraising to feature discussions and bug fixes. Here are the main highlights:
-
A significant donation from community member Tecman helped reach the goal for a server upgrade, demonstrating strong community support for the project.
-
Discussions about command-line argument parsing led to sharing of useful code snippets and potential future enhancements:
Public function MapIt(byref ipArray as variant, byref ipMapper as IMspper) dim myIndex as long For myIndex = Lbound(ipArray) to Ubound(ipArray) ipArray(myIndex)=ipMapper.execMapper(ipArray(myIndex)) Next end Sub
-
There were conversations about getting string values from enums and implementing first-class functions in VBA/twinBASIC, highlighting areas where developers are looking for more advanced language features.
-
A bug related to the
EOF
function in file handling was discussed and resolved, showcasing the community's collaborative problem-solving approach. -
The release of BETA 587 brought significant improvements to the
Array()
function, enhancing twinBASIC's array handling capabilities. -
Project lead Wayne Phillips returned after a brief pause in releases due to personal circumstances, promising a return to a more normal release schedule.
-
There was speculation about potential future directions for twinBASIC, including the possibility of generating XAML or C# code to leverage cross-platform frameworks like UNO.
In conclusion, this week saw continued refinement of twinBASIC's features, active community engagement in problem-solving, and discussions about future enhancements. The successful fundraising and return to regular releases indicate a healthy project with strong community support and ongoing development momentum.
Around the Web
Command-Line Parser Q&A
In the Discord chat, Greedo asked about the availability of a command line parser:
Has anyone made a command line parser they would be willing to share? Something that lets me define the --arguments or subcommands in an intuitive way, and then does all the hard work of escaping strings and converting data types to give a dictionary. Like python's argparse built-in libraries
wqweto offered the following response:
Btw, strings have to actually be unescaped and this is already done byCommandLineToArgvW
which other languages (C/C++, rust, etc.) run-times already use on Windows to parse command line intoargc
andargv
array.
Here is how this can be impl in VBx: https://github.com/Unicontsoft/UcsFiscalPrinters/blob/e64c6ca729ec5f3088fa6a5f13ad0da57dd0cde3/src/UcsFPHub/mdGlobals.bas#L232-L260
For a rudimentarygetopt
clone see this: https://github.com/Unicontsoft/UcsFiscalPrinters/blob/e64c6ca729ec5f3088fa6a5f13ad0da57dd0cde3/src/UcsFPHub/mdGlobals.bas#L410-L448
There is a dictionary returned though data-types for particular params have to be coerced by client code which in my experience has never been a significant problem.
Changelog
Here are the updates from the past week. You can also find this information by visiting the GitHub twinBASIC Releases page.
AI-Generated Changelog Summary
* Auto-generated via Claude-3.5-Sonnet, sorted in order of its opinion of "most impactful changes."
Here's a concise summary of the notable updates in twinBASIC:
-
Added array improvements:
- Support for
Array(Of T)
generic with type inference - Syntax support for array initializers
- Fixed-length arrays now support copy assignment
- Support for
-
Enhanced control features:
- New
Angle
property for Image and Shape controls (similar to Label.Angle) - Updated folder icons for DriveListBox
- New
-
Improved VB6/VBA compatibility:
- Better handling of Enum symbol resolving to match VBx behaviors
- Implemented
Implements T
behavior to align with VBx, including a new warning (TB0023) for field access
-
Fixed various issues:
- Resolved potential crashes in the expression engine
- Corrected dynamic array self-assignment behavior
- Addressed issues with Form properties and lightweight control mouse events
WARNING: The following issues are present in BETA builds 546 - 588 (the latest build as of publication):
- there are known memory leaks in these versions, so memory usage will be higher than normal
BETA 587
- improved: fault-tolerance in Ambient property implementations inside ActiveXExtender [ Lewis, discord ]
- improved: DriveListBox has new folder icons [ thanks sokinkeso! ]
- added: Image.Angle and Shape.Angle properties (same as Label.Angle)
- fixed: issue with Form inappropriately exposing Index property [ commissioned work ]
- fixed: VbCompareMethod.vbDatabaseCompare enum value was missing [ commissioned work ]
- improved: fixed-length arrays can now be copy-assigned (exact matching array bounds and type required)
- added: syntax support for array initializers (e.g.
Dim AnArray() = otherArray
) - fixed: expression engine potential crash during parsing in some circumstances
- added: support for Array(Of T) generic, with inference available in most cases (e.g.
Dim A() As Long = Array(1,2,3)
) - fixed: (regression) lightweight control mouse events could fire when Enabled or Visible property is False [ https://github.com//issues/1878 ]
- fixed: dynamic array self-assignment (
AnArray = AnArray
) would cause array to be emptied
BETA 588
- fixed: hard crash when trying to use a field initializer on a class/module scoped array value. Now throws compiler error [ wqweto, discord ]
- fixed: tweaked
Enum
symbol resolving priorities to better match VBx behaviours [ commissioned work ] - fixed:
Implements T
has to create an implicitPrivate T As T
field to match VBx behaviours, though using it generates a new warning TB0023 if field is accessed [ commissioned work ] - fixed: bogus debug console messages of
Unable to find ActiveX control $.controlName
in some imported VBP projects [ commissioned work ]