Code

Description

The Code node lets you execute custom VB.NET code directly within your workflow. It compiles user-written code on the fly using the VBCodeProvider and runs it in an isolated context. This is the ultimate "escape hatch" when no existing node does exactly what you need — string manipulation, math, conditional logic, data transformation, regex processing, etc.

The code is compiled only when it changes (cached internally), so subsequent executions are fast. You can route the results to multiple outputs, making it easy to split or branch data programmatically.


Configuration Properties

💻 Code Editor (Scintilla)

Text Editor
A full-featured code editor with syntax highlighting (Scintilla.NET). It comes pre-filled with a template you must respect:

Public Class UserCode
    Public Function Process(inputs() As String) As String()
        Return inputs
    End Function
End Class

The class must be named UserCode and contain a Public Function Process that takes a String() array and returns a String() array. Each element of the returned array is sent to the corresponding output anchor.

Automatically imported namespaces (no need to add Imports for these):

  • System
  • System.Collections.Generic
  • System.Linq
  • System.Text
  • System.IO
  • System.Threading
  • System.Threading.Tasks
  • Microsoft.VisualBasic

🔢 Output Count Section

Numeric Up/Down (default: 1)
Defines the number of output anchors. The Process function must return an array with exactly this many elements. If the returned array is shorter, missing outputs send empty strings; if longer, extra elements are ignored.


🔨 Compilation Section

Reset
Clears the compiled assembly cache and resets the status to "Ready." Forces a full recompilation on the next run.

Compile
Manually triggers compilation of the current code. Errors (if any) appear in the Errors panel at the bottom. Successful compilation updates the status to "Compiled."

💡 Tip: You don't have to click Compile manually — the node auto-compiles on first execution if the code has changed since the last run. The button is just for preview/debugging.


📊 Status Section

Status Label
Displays the current compilation state:

  • Ready. — code not yet compiled (or reset).
  • Compiled. — code compiled successfully, ready to execute.
  • Error. — compilation failed; see the Errors panel for details.

️ Options Section

Use First Input as code
When checked, a second input anchor appears on the node:

  • Anchor 0 receives the VB.NET source code (as a string, e.g., from a FileReadNode or TemplateNode).
  • Anchor 1 receives the actual data to process.

This allows you to dynamically change the code at runtime without opening the config dialog. When unchecked, only one input anchor exists (the data), and the code comes from the editor.


❌ Errors Panel

Text Area (bottom)
Displays compilation errors with line numbers and descriptions when the code fails to compile. Empty when compilation succeeds.


Usage Example

"Split a CSV line into columns":

  1. An Input node receives: Alice,30,Engineer
  2. A Code node with:
Public Class UserCode
    Public Function Process(inputs() As String) As String()
        Dim parts() As String = inputs(0).Split(","c)
        Return parts
    End Function
End Class
  • Output Count: 3
  1. Three Output nodes display: Alice, 30, Engineer

Pitfalls to Avoid ⚠️

Wrong class or function signature: The compiler expects exactly Public Class UserCode with Public Function Process(inputs() As String) As String(). Any deviation (different class name, Sub instead of Function, wrong parameter type) will fail to compile.

Output Count mismatch: If you set Output Count = 3 but your Process function returns only 2 elements, the third output will be empty. Always match the array size to the output count.

Heavy computations block the workflow: The code runs synchronously on the executor thread. A long-running loop (e.g., processing thousands of lines) will freeze the entire workflow until it finishes. Keep code lightweight; offload heavy work to external tools or break it into smaller steps.

No sandboxing: The compiled code runs with the same permissions as TzuFlow itself. Malicious or buggy code can read/write files, crash the app, or cause infinite loops. Only use code you trust or have tested.

Use First Input as code + empty input: If you enable this option but nothing is connected to anchor 0, the node receives an empty string as code and compilation will fail. Always ensure a valid code source is connected.

Recompilation overhead: While the node caches the compiled assembly, any change to the code (even a single character) forces a full recompile. Avoid editing the code during a long-running loop — it will recompile on every iteration if Reset is triggered.