Variable Handling
🔗 Original page — Source for this material
Description

A variable is a memory container that can hold a set or calculated value. In ZennoPoster, you can create variables, rename them, delete them, and assign various values to them. The easiest way to work with variables is through the ❗→ Variables Window.
You should distinguish between C# variables, which are strictly typed, and project variables, which are not strictly typed. However, the values of these two types of variables can always be converted without any data loss or distortion.
Variables are the foundation of any project in programming.
How do I add an action to a project?
Via the context menu, choose Add action → Data → Variable handling

Or use the ❗→ smart search.
What are they used for?
- To set and change variable values.
- To increment or decrement counter variables.
How to work with this action?
Set value

You can assign a variable a static string, number, the value of another variable, the value of an environment variable, or any combination of the above.
Increase/Decrease counter
The counter mode supports both incrementing and decrementing the value. You can increase or decrease the counter not just by one, but by any number specified in the "Value" field. The chosen variable in the "Variable Name" field will have its value increased or decreased.
Clear variables
Added in ZennoPoster 7.7.0.0
With this action, you can clear the contents of variables.
There are 3 clearing modes:
- All
- Listed only
- All except those listed
This is useful, for example, when a template is running in a loop and you need to clear variable data before starting a new iteration so that values from the previous phase do not carry over to the next one.
Global variables and Namespace
Regular variables are only visible within one project thread (if the project runs in multithreaded mode, each thread will have its own local and independent variable).
Global variables, on the other hand, are available to all projects and their threads in ZennoPoster.
To avoid confusion, global variables have an additional property—a namespace—which must be specified whenever you create or reference them.
Example use cases
Let’s look at a few practical examples of using variables in projects.
Assigning a value to a variable
You can assign or change a variable’s value either in the special ❗→ Variables Window, or via the “Data“ → “Variable handling“ block.

In this example, an email address is formed by combining string variables for the login and website domain.
Working with a counter variable and environment variables
Let’s imagine a scenario where we need to generate a list of ten current timestamps.

- Create a variable called
countto serve as a counter and assign it the value0using the “Variable handling“ block. - Using the same block, get the current timestamp with the ❗→ environment variable
{ -TimeNow.TimeNow- }. Add it to thetimevariable and save the result back totime. - Now, repeat the procedure from step 2 nine more times. To do this, use the “IF“ block to compare the value of the
countcounter to the maximum value9using ❗→ IF (If... Then...). - If the condition is not met (counter is less than or equal to 9), increase
countby1with the “Variable handling“ block (“Increase counter” option) and repeat step 2. - If the condition is met (counter is greater than 9), finish processing and output the result of the
timevariable to the log. You can view the result in the ❗→ Variables Window
Useful links
- ❗→ Variables Window
- Using variables – YouTube link.
- Variable initialization – YouTube link.
- Deleting a variable from a project – YouTube link.
- Counter variable – YouTube link.
- Getting a variable’s value – YouTube link.