u/ws-garcia

The future of VBA language isn’t about replacing it. It’s about supercharging it.
▲ 9 r/vba

The future of VBA language isn’t about replacing it. It’s about supercharging it.

Recently, I engaged with a Redditor about the usefulness of ASF in daily VBA programming. The conversation considered the increasing number of attempts to modernize VBA. There are many solutions out there providing tools to users with specific goals: parsing json files, dealing with file encryption, evaluating expressions.

Despite that, very few authors focus their efforts to tackle the oldest pain point for VBA programmers: the frozen primitives (array, collection, dictionary), the motivation for the vast majority of boilerplate code. From this, specialized tools like u/senipah VBA Better Array, u/sancarn stdVBA, u/cristianbuse VBA Array Tools, Tim hall VBA JSON and many others came about. Almost all these libraries can be placed in the tooling category, since they focus on dealing with a specific problem (with the exception of stdVBA for being a framework to make VBA more ergonomic and kill VBA boilerplate code).

Those incredible projects have served as inspiration for many developers and paved the road for new projects that modernize VBA. ASF inherited some of those authors' philosophies, especially the one shown by u/sancarn: make code more ergonomic and go far beyond being a simple tool. As an example, here is a test from a 400+ test suite available for this scripting language:

'@TestMethod("sort")
Private Sub sort_chain_on_objects()
    On Error GoTo TestFail
    Dim Globals As ASF_Globals
    Dim jsonResponse As String
    jsonResponse = _
        "{" & _
        "  users: [" & _
        "    { id: 1, name: 'Alice', sales: 15000, active: true }," & _
        "    { id: 2, name: 'Bob', sales: 8000, active: false }," & _
        "    { id: 3, name: 'Charlie', sales: 22000, active: true }" & _
        "  ]" & _
        "};"
    GetResult "let response = " & jsonResponse & _
        "let topSellers = response.users" & _
        "  .filter(fun(u) { return u.active && u.sales > 10000 })" & _
        "  .map(fun(u) { return { name: u.name, bonus: u.sales * 0.1 } })" & _
        "  .sort(fun(a, b) {" & _
        "    if (a.bonus > b.bonus) { return -1 };" & _
        "    if (a.bonus < b.bonus) { return 1 };" & _
        "    return 0;" & _
        "  });" & _
        "print(topSellers);", True
    Set Globals = scriptEngine.GetGlobals
    With Globals
        actual = CStr(.gRuntimeLog(.gRuntimeLog.Count))
    End With
    expected = "PRINT:[ { name: 'Charlie', bonus: 2200 }, { name: 'Alice', bonus: 1500 } ]"
    Assert.AreEqual expected, actual
TestExit:
    Exit Sub
TestFail:
    Assert.Fail "Test raised an error: #" & err.Number & " - " & err.Description
    Resume TestExit
End Sub

I think if we, as a community of people that really love VBA, can improve our loved language even more, we can make possible that which almost all people think impossible. As an example, we have Web View embedding web pages in userforms and inspiring a new development generation!

u/ws-garcia — 21 hours ago
▲ 10 r/vba

ASF: Introducing shared COM prototyping in VBA

After a hiatus in development, during which I devoted a great deal of time to other applications and studies, I am pleased to introduce ASF v3.1.3. This version offers improved usability and introduces the ability to share hacks on native Office COM objects, making prototypes fully portable across modules. Prototype definitions can now be exported and imported like any other ASF symbol, enabling shared prototype libraries. Here is an example of how this new feature works:

// prototypes.vas
export prototype.COM.Range addStyle(color) {
    this.Interior.Color = color;
};

export prototype.COM.Worksheet highlight(rng, color) {
    rng.addStyle(color);
};

// main_prototype.vas
scwd(wd);
import { Range_addStyle, Worksheet_highlight } from './prototypes.vas';
// Prototypes are live immediately after import
let ws = $1.ActiveSheet;
let rng = ws.Range('J1:L3');
rng.addStyle(65535);          // yellow
ws.highlight(rng, 255);       // red
return rng.Interior.Color

Here is the driving VBA code:

Private Sub module_system_prototype_imports()
    Dim result As Long
    Dim wd As String
    Dim eng As New ASF
    wd = ThisWorkbook.path
    With eng
        .AppAccess = True
        .InjectVariable "wd", wd
        result = CLng(.Execute(wd & "\main_prototype.vas", ThisWorkbook))
    End With
    'Expected: 255
End Sub

And here is the execution trace:

=== Runtime Log ===
RUN Program: 
CALL: ActiveSheet() -> <Worksheet>
CALL: range('J1:L3') -> <Range>
CALL: addstyle(65535) -> 
CALL: __PROTOTYPE_RANGE_ADDSTYLE(65535) -> 
CALL: Interior() -> <Interior>
CALL: highlight(<Range>, 255) -> 
CALL: __PROTOTYPE_WORKSHEET_HIGHLIGHT(<Range>, 255) -> 
CALL: addstyle(255) -> 
CALL: __PROTOTYPE_RANGE_ADDSTYLE(255) -> 
CALL: Interior() -> <Interior>
CALL: Interior() -> <Interior>
CALL: Color() -> 255
CALL: @anon() -> 255
u/ws-garcia — 4 days ago