EN RU
Log in
Home
Download
Purchase
Documentation
Support
Contact us
 
Help  /  FAQ

Use of local variables

Local variables are used to save and substitute strings and numbers during the installation of a program. Practically all the installer’s commands work with local variables. Commands can record and receive values from specified variables. If a command requires you to define a parameter or variable, just specify the name using Latin letters, numbers and underscores (‘_’).

myvar1
my_variable
MyVar

If you need to substitute the value of a variable, you need to specify its name between the two pound signs (‘#’) For example, if the variable myvar contains the value Test value, the string Value = #myvar# will be assigned to the string Value = Test value. If the variable's value contains other variables, they will also be replaced by the corresponding values. If a nonexistent variable #anyvar# is specified, this fragment will remain as is.

Let's look at an example. Say you have the following variables and specified values:

mypar1 = Parameter 1
mypar2 = #mypar1# + Additional parameter
mypar3 = Parameters: #mypar1#, #mypar2#, #mypar#

In this case, #mypar3# will be replaced by the following line.

Parameters: Parameter 1, Parameter 1 + Additional parameter, #mypar#

As you see, #mypar# was not changed, as the variable mypar is not defined.

Use of local variables as arrays

Variables can be seen as arrays of strings. Say you have the variable myarr, which contains several strings.

This is the first line.
c:\temp\subfolder\myfile.txt
param1|Parameter 2|parameter 3

If you specify #myarr# in the script, all three specified strings will be substituted. What should you do if you need to substitute only the first or third string? It is enough to just specify the variable name, point and string number. Strings are numbered starting from 0. In our case, #myarr.1# returns c:\temp\subfolder\myfile.txt. Besides a numeric value, you can specify a variable name, the value of which equals the number of the necessary string. If myid equals 0, then#myarr.id# returns This is a first line..

It should be noted that a variable’s value is not seen as a string array, but as a two-dimensional array, in which strings are split into substrings with a delimiter character. To get such a substring, you need to use an entry in the form #varname.[idx][delimeter][idy]#, where idx is the number of the string, [delimeter] is the delimiter character and idy is the number of the fragment in the string from 0. idx and idy can be numbers or variable names. The delimiter can be any character except for a number or letter. Now look at the results, which will be returned after the following calls to the variable myarr.

#myarr.0 3#  => first
#myarr.1\0#  => c:
#myarr.1\2#  =>  subfolder
#myarr.2|subid#  =>  Parameter 2     (if the variable subid equals 1)
#myarr.2|0#  => param1
#myarr.id1 id2#  => line. (if the variable id1 equals 0 and id2 equals 4)

See also

  • Global and local variables
  • Predefined folders
  • Predefined variables
Eonza automation software - free, open source cross-platform program for easy creation and management of scripts.
  • Help
    • Introduction
    • Get to know CreateInstall
    • Compare installers
    • License Agreement
    • License Light
    • License Free
    • Program features
    • Command Reference
    • FAQ
      • Antivirus false positives
      • Command Prompt Mode
      • How to create shortcuts
      • How to get Control ID
      • How to sign an installation
      • How to use environment variables
      • Installing 64-bit applications
      • Local variables
      • Portable version
      • Unpacking filter
      • Common dialog parameters
      • Custom dialog function
      • Global variables
      • How to move and resize controls
      • How to use If Condition
      • Language-dependent variables
      • Multi build setups
      • Predefined folders
      • Predefined variables
      • Variables of dialogs
    • Examples & tips
    • CreateInstall Assistant
    • Problem solving
    • Setup Extractor
Copyright © Novostrim, OOO, 2009-2026 All rights reserved.