uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

VB

Product: 

Class: 

Covers VB.NET-specific features, syntax, and lifetime management patterns when using the uCalc library.

Remarks

💎 Idiomatic VB.NET Features

While uCalc is designed with a consistent cross-platform API, it offers several features that integrate seamlessly with VB.NET idioms, providing a more natural and productive development experience.

1. Properties vs. Methods

Many uCalc members documented as properties (getters/setters) can be accessed using standard VB.NET property syntax (=) instead of method calls (()). This provides cleaner, more readable code.

FeatureVB.NET SyntaxC++ Syntax
Setteruc.Description = "text"uc.Description("text");
GetterDim d = uc.Descriptionvar d = uc.Description();

For a detailed overview, see the Properties / Getters / Setters topic.

2. Indexers (())

Collections like Tokens and Matches support VB.NET indexers (()) for direct access to elements. This is a convenient shortcut for methods like ByName() or At().

' Instead of this:Dim token = uc.ExpressionTokens.ByName("_token_alphanumeric")' You can write this:Dim token = uc.ExpressionTokens("_token_alphanumeric")

3. For Each Loop Integration

All uCalc collection objects (e.g., Matches, Tokens, Items) implement IEnumerable. This means you can iterate over them directly using a standard VB.NET For Each loop, which is simpler and safer than a manual For loop with an index.

For Each rule In myTransformer.Rules    wl(rule.Name)Next

4. Lifetime Management with Using

This is the most critical VB.NET-specific pattern. Most uCalc objects hold unmanaged resources and must be released to prevent memory leaks. While you can call Release() manually, the idiomatic VB.NET approach is to wrap object creation in a Using block. All major uCalc objects implement IDisposable, which guarantees that Release() will be called automatically when the object goes out of scope.

' The transformer 't' will be released automatically at the end of the block.Using t = uc.NewTransformer()    wl(t.Transform("input"))End Using ' t.Release() is called here.

This is the VB.NET equivalent of the C++ RAII pattern using Owned().

5. Implicit Conversions & Constructors

For convenience, several uCalc classes provide implicit conversions from String, allowing for more concise initialization.

  • uCalc.String: Dim s As uCalc.String = "initial text"
  • uCalc.Expression: Dim expr As uCalc.Expression = "1 + 1"
  • uCalc.Transformer: t.Text = "input" can be shortened to t = "input".

The Expression and String classes also have constructors that accept a string, which provides a familiar VB.NET object creation pattern that implicitly uses the default uCalc instance.

' These two are equivalent, using the default uCalc instance.Dim expr1 = uc.Parse("5 * 2")Dim expr2 = New uCalc.Expression("5 * 2")

6. XML Literals

VB.NET's unique support for XML Literals provides a highly readable way to construct the complex strings often used in Define calls. Because XML can be multi-line and handles quotes automatically, it's an excellent way to define functions with embedded documentation or complex transformer rules.

Dim funcDef = <define>                  Function: LogWithTimestamp(msg As String) =                      '[' + Now() + '] ' + msg              </define>.Value' The .Value property extracts the inner text of the XML literal.uc.Define(funcDef)

🆚 Comparative Analysis: Why uCalc in VB.NET?

While VB.NET is a powerful language, uCalc provides specialized capabilities not available natively:

  • Runtime Parsing vs. DataTable.Compute: The common .NET workaround for evaluating strings, DataTable.Compute, is slow, limited to simple arithmetic, and lacks features like custom functions or operators. uCalc is a high-performance, full-featured parsing engine.

  • Dynamic Language Definition: VB.NET is statically compiled. uCalc allows you to define new functions, operators, and even token syntax at runtime, enabling the creation of dynamic scripting environments and Domain-Specific Languages (DSLs) within your VB.NET application.

  • Token-Aware Transformations: VB.NET's Regex class is powerful for character-level patterns but struggles with nested structures and language context. uCalc's Transformer operates on tokens, making it inherently aware of code structure (parentheses, strings, comments), which is far more robust for code transformation and analysis.

Examples

A succinct demonstration of core VB.NET idioms: `Using` for lifetime management, property syntax, and implicit string conversions.
				
					using uCalcSoftware;

var uc = new uCalc();


// This example is meant for VB.NET only
Console.WriteLine("Description: My VB.NET uCalc instance");
Console.WriteLine("Transformer Text: Hello Again");
Console.WriteLine("Transformer Text: Hello Again");

				
			
Description: My VB.NET uCalc instance
Transformer Text: Hello Again
Transformer Text: Hello Again
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;


   // This example is meant for VB.NET only
   cout << "Description: My VB.NET uCalc instance" << endl;
   cout << "Transformer Text: Hello Again" << endl;
   cout << "Transformer Text: Hello Again" << endl;

}
				
			
Description: My VB.NET uCalc instance
Transformer Text: Hello Again
Transformer Text: Hello Again
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      
      ' 1. Automatic resource management with 'Using '
Using u = New uCalc()
    ' 2. Property syntax for setting the description
    u.Description = "My VB.NET uCalc instance"
         Console.WriteLine($"Description: {u.Description}")
         
         ' 3. Implicit String conversion for Transformer.Text
    Dim t As New uCalc.Transformer()
    t.Text = "Hello World" ' Standard assignment
         t = "Hello Again"    ' Implicit conversion assignment
         Console.WriteLine($"Transformer Text: {t.Text}")
         Console.WriteLine($"Transformer Text: {t}")
      End Using
      
      
   End Sub
End Module
				
			
Description: My VB.NET uCalc instance
Transformer Text: Hello Again
Transformer Text: Hello Again