twinBASIC Update: December 12, 2021
Highlights include the File I/O system reaching feature-complete status, an updated twinBASIC roadmap, and experimental text encoding support.
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.
Additional File System Features Implemented
Last week saw continuing work on the File System features of VBx, both in terms of language statements and standard library methods. Here's an updated list of implemented features with newly implemented features from this week in bold:
Language Statements Implemented
- Open (Binary / Random modes only)
- Input #
- Width #
- Line Input #
VBA.FileSystem Library Members Implemented
- CurDir / CurDir$
File System Features Not Yet Implemented
The VBx file system portion of twinBASIC is now feature-complete!
However, Wayne has some twinBASIC-exclusive file system features on the development roadmap, including:
Customizable Text Encoding – Experimental
If you're not sure why this matters, please read this now-decades-old piece from Joel Spolsky: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).
This feature is currently in the experimental stages. Here's a quick sample from Wayne:
Open "Z:\unicodeTest.txt" For Output Encoding "utf-8 BOM" As #1 Print #1, "Hello from twinBASIC! 😎" Close #1 Dim myString As String Open "Z:\unicodeTest.txt" For Input Encoding "utf-8 BOM" As #1 Line Input #1, myString Close #1 Debug.Print "FILE DATA: " & myString
Encoding "utf-8 BOM" portion of the Open commands above is not valid VBx syntax. That's the part that's new in twinBASIC. And, in fact, the above code probably won't be valid twinBASIC syntax for long, either, as the "utf-8 BOM" string parameter will likely be replaced with an enumeration, such as
Encoding.encUtf8. Stay tuned!
Big File Support – On the Roadmap
Native VBx file handling breaks on all files larger than 4GB.
Wayne summarized the problem and highlighted the scope of a potential fix:
Currently, file positions are considered 32-bit wide and that limits the maximum allowed file size supported by VBx and tB. There are several areas of the syntax that need to be tweaked, and of course several of the library functions will also need to be tweaked, or extended versions provided.
Wayne stated that he would look into implementing this in Q1 2022.
Go To Definition Now Works on Line Labels
Using the "Go to Definition" feature in VS Code, you can now jump directly to the line labeled
MyLabel when you press [F12] on the code:
GoTo MyLabel. This is not something you can do in the VBA IDE.
Around the Web
twinBASIC 12-Month Roadmap Updated
Two days ago, Wayne updated the twinBASIC Roadmap to indicate which features have been implemented as well as which items are still on the to-do list.
The following items have been completed so far:
Forcing Windows to Update Your .EXE's Icon
Apparently, Windows Explorer caches icons embedded in .exe files. So, if you change the icon of a compiled twinBASIC .exe project after you've already compiled it at least once, then Windows will continue showing the old icon.
Leave it to Wayne to know the command to force Windows to clear the Windows Explorer icon cache:
Destructuring Assignment Support Requested
I'll admit, I had to look up what "Destructuring Assignment Support" meant, but it's basically a way to assign multiple results from a function to multiple variables on the left-hand-side of an expression.
You can sort of do this in VBA now by declaring a user-defined type (UDT) and passing that as the return type of a function, but it has its own limitations (and requires explicitly declaring the UDT).
You can also sort of do this by returning an array as a Variant and assigning it to a Variant on the left-hand side of the expression. This approach lacks type safety and other compile-time safety, such as matching the number of items on each side.
The shortcomings from both workarounds described above would be addressed if twinBASIC supported Vladimir Vissoultchev's (wqweto on GitHub) request:
There is some precedent for this type of syntax in VBx, as evidenced by the Mid statement.
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.13.30, 11th December 2021]
- improved: Go To Definition now works with line labels and line numbers [ https://github.com/WaynePhillipsEA/twinbasic/issues/554 ]
- fixed: Module based UDTs now wont be exposed in the public type library, matching VB6 behaviour [ https://github.com/WaynePhillipsEA/twinbasic/issues/552 ]
[v0.13.29, 10th December 2021]
- fixed: build crash in some instances [ https://github.com/WaynePhillipsEA/twinbasic/discussions/550 ]
- improved: 'unable to find DLL entry point' error is now displayed in the debug Console, rather than via a MsgBox
[v0.13.28, 10th December 2021]
- fixed: terminating a debug session while stepping through code often caused a compiler-restart (64-bit only)
- fixed: LSP bad JSON encoding for codeLens feature when an identifier contained a double-quote, causing LSP re-connection and IDE flickering [ https://github.com/WaynePhillipsEA/twinbasic/issues/545 ]
[v0.13.27, 10th December 2021]
- improved: Debugger now auto-closes any open file handles when destroying global variables upon a debug session being ended
- added: experimental support for Encoding argument in file Open statement (e.g. Open xyz For Output Encoding "utf-8" As #1) 
- fixed: Val() to be locale-independent [ https://github.com/WaynePhillipsEA/twinbasic/issues/543 ]
- fixed: #Const conditional expression evaluation not enforcing Option Explicit Off in the conditional compilation context [ https://github.com/WaynePhillipsEA/twinbasic/issues/544 ]
- fixed: correction to handling of ending comma / semi-colon on Print and Write statements
- improved: added support for Debug.Print ending comma / semi-colon [ https://github.com/WaynePhillipsEA/twinbasic/issues/223 ]
[v0.13.26, 9th December 2021]
- added: Width # syntax support [ https://github.com/WaynePhillipsEA/twinbasic/issues/279 ]
- fixed: Line Input # off-by-one EOF issue [ https://github.com/WaynePhillipsEA/twinbasic/issues/542 ]
- improved: Input # and Line Input # performance [ https://github.com/WaynePhillipsEA/twinbasic/issues/542 ]
[v0.13.25, 8th December 2021]
- fixed: Dir(filePath) not working as expected when filePath file does not exist [ https://github.com/WaynePhillipsEA/twinbasic/issues/279#issuecomment-988207525 ]
- fixed: Name-As syntax clashing with legal use of Name as procedure or variable name [ https://github.com/WaynePhillipsEA/twinbasic/issues/541 ]
- added: LineInput # syntax support [ https://github.com/WaynePhillipsEA/twinbasic/issues/279 ]
[v0.13.24, 7th December 2021]
- added: VBA.FileSystem.FileCopy / Dir / Kill implementations [ https://github.com/WaynePhillipsEA/twinbasic/issues/279 ]
- added: Name X As Y (file/folder rename) syntax [ https://github.com/WaynePhillipsEA/twinbasic/issues/279 ]
[v0.13.23, 7th December 2021]
- added: VBA.FileSystem.ChDir / ChDrive / CurDir$ / CurDir implementations
- fixed: codegen error when an As-New variable was passed as a ByRef argument (property-set RHS) [ https://github.com/WaynePhillipsEA/twinbasic/issues/535 ]
[v0.13.22, 7th December 2021]
- improved: codegen errors now include the line number of the first line of code that caused the codegen failure [ https://github.com/WaynePhillipsEA/twinbasic/issues/535 ]
- fixed: miscompilation of Decimal to LongLong / Double conversions in some instances (32-bit only)
- fixed: IDE auto insertion of block terminators were incorrectly indented after some unicode characters appeared in the source code [ https://github.com/WaynePhillipsEA/twinbasic/issues/530 ]
[v0.13.21, 6th December 2021]
- fixed: fixed compiler crash with Return when does not return a value (e.g. Sub routine) [ https://github.com/WaynePhillipsEA/twinbasic/issues/534 ]
- fixed: VS Code extension configuration editor now prevents setting the 'inherits' option incorrectly [ https://github.com/WaynePhillipsEA/twinbasic/issues/533 ]
[v0.13.20, 6th December 2021]
- added: support for Input # statement [ https://github.com/WaynePhillipsEA/twinbasic/issues/279 ]