twinBASIC Update: February 12, 2023

Highlights include an improved UX for selecting one control from a group of controls, an update to the ActiveX Control project type, and some IID advice.

twinBASIC Update: February 12, 2023

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

Easier Selection of Stacked Controls

In a recent article, I wrote about the challenge of selecting the bottom control in an Access form when multiple controls are stacked on top of each other.

Quick Tip: 4 Ways to Select the Bottom Control in a Stack
There are many situations that call for two (or more) controls to be stacked on top of each other. In those situations, how does one select the bottom control?

BETA 247 introduces a new feature with a clever solution to this problem:

when multiple controls are selected in the form designer, the control selector drop-down list now only lists the selected controls

Updated ActiveX Control Project Type

BETA 247 "added explicit project type of 'ActiveX Control', defaulting to OCX file extension and controlling the LIBFLAG_FCONTROL type library flag."

Here's some context from Discord:

[fafalone] One thing that's strange... [my zxTBShellTreeControlCtl] is the only control that's added itself to References in addition to components... the VB-compiled versions don't do this

[Wayne] VB6 only does this when the type library doesn't have the LIBFLAG_FCONTROL flag set.  (more specifically, it checks the registry for the FLAGS value registered for the type library, which should be the same value as stored in the type lib).     tB BETA 247 introduces an explicit ActiveX Control project type, which will set this flag (and also will default to OCX file extension) to match VB6.

Around the Web

Registering an ActiveX Control for 32-bit and 64-bit Office Use on Same Machine

I'm including these comments from Wayne mainly as a note to myself as I have a feeling I will be looking for this information sometime in the future:

@fafalone coming back to the VBA UserForm problems you were having with your Ax control.  I managed to compile your zTBucShellBrowse control and got it working in both 32-bit and 64-bit Office (on same machine).  The trick is to make sure all of your IIDs match when you compile to both bitnesses, otherwise VBA generates strange runtime errors.  It appears that VBA 64-bit will prefer to load the registered 32-bit version of a type-library, if it's registered.  This is problematic, because if you don't specify all the IIDs explicitly, the auto-generated ones that tB assigns will be different for each build/bitness.

In addition to this complication, the VBA IDE seems to cache typelib component information when you add a component to the toolbox, so it is advisable to start afresh... first assign a new project ID (GUID) in your project settings as this is used for the typelib GUID, and then make sure you've got all of these attributes set on your component Class:   ClassId, InterfaceId, EventInterfaceId.  Generate new GUIDs for each of them before building your project again.  In addition, I also changed the name of the class itself and the output filenames, just to make sure VBA's cache didn't interfere with anything, but that probably is not necessary.

Once you've done the above, compile to both 32-bit and 64-bit, and fingers crossed, it should work.

The main issue is that twinBASIC will generate IIDs at build time if they are not present in the code.  Since 32-bit and 64-bit versions of an ActiveX control must be built separately, they will end up with different IIDs unless you explicitly set them in code.

Wayne's conversation with fafalone continued as follows:

[fafalone] did i use different IIDs for different bitnesses when it didn't work? i don't recall

[Wayne] If you don't explicitly set the IIDs, you'll get random ones issued by tB at build time.

[fafalone] i have the 'use project id as typelib id' option enabled for all of them; is there something else that needs to be done?

[Wayne] Yes, you need to add the InterfaceId and EventInterfaceId attributes to your class, e.g.
[ FormDesignerId ("8CE9DEA3-CF96-4344-87A8-3F6F9ECBBD42") ]
[ ClassId ("807A2B67-AEE2-44B9-BA11-96D73EDD2A19") ]
[ EventInterfaceId ("1D20C84A-3902-42F4-AAC2-556761CD4206") ]
[ InterfaceId ("6CD64463-6F47-4DDD-BDC3-F03EC4151768") ]
[ COMControl ]
[ Description ("zTBucShellBrowse Control 12.0 R1") ]
Public Class zTBucShellBrowse2

It appears the compiler warning added in BETA 245 is meant to address this situation:

  • added: new compiler warning TB0013: "it is strongly recommended to specify an [ InterfaceId() ] attribute for this class"

Wayne's final comment in his conversation with fafalone might save you (or me) some frustration in the future:

Just remember to change all the GUIDs, because the VBA cache is a pain.

Changelog

Here are the updates from the past week.  You can also find this information by visiting the GitHub twinBASIC Releases page.

Releases · WaynePhillipsEA/twinbasic
Contribute to WaynePhillipsEA/twinbasic development by creating an account on GitHub.

WARNING: The following issue is present in BETA builds 202 - 249 (the latest build as of publication):

  • there are known memory leaks in these versions, so memory usage will be higher than normal

BETA 243

  • fixed: generated typelibraries with extended interfaces sometimes had an extra bogus first member
  • added: support for [ ComImport(Boolean) ] attribute on interface/class/coclass for controlling the automatic registration behaviour of types in DllRegisterServer

BETA 244

  • fixed: (regression) runtime error when showing a form involving lightweight controls in some instances [ fafalon, discord ]
  • fixed: don't generate type library for Standard EXE projects [ https://github.com//issues/1476 ]
  • fixed: DataObject/DataObjectFiles/DataObjectFormat/DataObjectFormats were wrongly defined in WinNativeForms(VB) rather than VBRUN
  • fixed: (ActiveX controls) workaround for VB6 passing IPersistPropertyBag.Save a property bag that can't handle 'Nothing' IUnknown/IDispatch without crashing
  • added: implementation for UserControl.ActiveControl [ fafalone, discord ]
  • added: implementation for UserControl.Count [ fafalone, discord ]
  • added: unimplemented placeholders for UserControl.PaintPicture/Point/Scale/PropertyPages [ fafalone, discord ]
  • fixed: some UserControl window invalidation issues on moving/resizing [ sokinkeso, discord ]

BETA 245

  • fixed: UserControl with ClipControls set had visual glitches with PictureBox controls when the UC was resized [ fafalone, discord ]
  • fixed: IDE syntax highlighting was sometimes inactive if code was collapsed via code folding
  • fixed: IDE syntax highlighting was sometimes inactive for the sticky-scroll entries
  • fixed: cursor(.CUR) files put into the Resources\CURSOR folder were not correctly embedded into generated executables [ Tecman, private ]
  • fixed: project setting 'Startup Object' was incorrectly including UserControls in the available startup forms list
  • fixed: [ COMControl ] attribute was missing on imported UserControls [ Tecman, private ]
  • fixed: [ InterfaceId ] and [ EventInterfaceId ] attributes were missing on imported UserControls [ fafalone, discord ]
  • added: new compiler warning TB0013: "it is strongly recommended to specify an [ InterfaceId() ] attribute for this class"

BETA 246

  • improved: compiler errors of 'unable to match this handler to its event member' now include the expected procedure signature when possible [ Tecman, discord ]
  • fixed: ScaleWidth/ScaleHeight in the form designer were showing zero for UserControls [ Tecman, discord ]
  • fixed: typo in compiler warning TB0012: "possible misuse of hexadecimal literal notation..."
  • improved: compiler warnings and errors all now start with a capital letter
  • fixed: TypeLib generation was filling in the FUNCDESC.cParamsOpt field incorrectly in some instances [ https://github.com//issues/1473 ]
  • added: ActiveX wrappers now support SetFocus method [ DinyaZ, discord ]
  • fixed: (regression) setting ScaleMode at runtime causes failure regarding ambient-property updates [ https://github.com//issues/1479 ]
  • fixed: RaiseEvent event names not auto-corrected to match the case of the definition [ https://github.com//issues/1468 ]
  • fixed: PictureBox and Image default-member properties were read-only [ https://github.com//issues/1467 ]

BETA 247

  • improved: added explicit project type of 'ActiveX Control', defaulting to OCX file extension and controlling the LIBFLAG_FCONTROL type library flag
  • fixed: [PreservedSig] entries would sometimes show incorrectly in TypeLib viewer [ fafalone, discord ]
  • fixed: checked-ListBox error when clicking outside of the items area [ https://github.com//issues/1480 ]
  • fixed: IgnoreWarnings/EnforceWarnings/EnforceErrors attributes were not effective for warnings after TB0009 (i.e. TB0010 onwards) [ Tecman, discord ]
  • fixed: EOF() would return False on opening an empty file for Input [ https://github.com//issues/1481 ]
  • fixed: VBA UserForms toolbox now shows tb-generated components' toolbox icons
  • fixed: UserControl class descriptions ([Description("")] or Attribute VB_Description = "") now gets registered properly in our custom RegisterTypeLib implementation
  • fixed: DllUnregisterServer could leave behind some ProgID entries during cleanup [ TecMan, discord ]
  • improved: when multiple controls are selected in the form designer, the control selector drop-down list now only lists the selected controls [ GrandPaM, discord ]
  • improved: tweaked the recent-file error dialog [ https://github.com//issues/1482 ]

BETA 248

  • added: support for ZOrder method on all controls

BETA 249

  • fixed: (regression) lightweight controls leaking COM references at runtime
  • fixed: form designer issue when Font.Size is not integral, causing problems on machines where dot (.) is not the decimal symbol in regional settings

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