# VIA Assign Variable Indirectly

> Source: https://manual.pvxplus.com/directives/via

## Formats

|  |  |  |
| --- | --- | --- |
| 1\. | [Assign to Variable](https://manual.pvxplus.com/directives/via#Mark5)*:* | **VIA** *var$=expression\[*, *var$=...***\]** |
| 2\. | [Assign to Composite Variable](https://manual.pvxplus.com/directives/via#Mark8)*:* | **VIA** *composite$,var_1$*\[\[,*subscr*\]\]*=expression*\[,...*n*\]<br>Note:  <br>The inner set of brackets enclosing \[,subscr\] are part of the syntax. |

***Where:***

|  |  |
| --- | --- |
| *composite$* | Composite string variable. (Name of a variable defined as composite string.). |
| **\[**,*subscr*\] | Optional subscript(s) of a variable in the composite string. String expression. You can include from 1 to 3 optional numeric expressions in square brackets, comma-separated, as subscripts for the variable. |
| *expression* | Value you want assigned to the named variable. |
| *var$* | String variable containing the name of the variable to be used. |
| *var_1$* to *var_2$* | String expression containing the name of a variable in the composite string. |

## Description

Use the **VIA** directive to assign a value to a variable where the variable name is contained in another string variable. The target variable's type (numeric or string) is based on the type of expression.

## Format 1

***Assign to Variable***

**VIA** *var$=expression*

Use this **VIA** format to assign the value in the expression to a variable whose name is stored in *var*$ (i.e. to assign **VIA** the *var$*).

If you use a string, then PxPlus automatically appends a **$** (*dollar sign*) to the variable name. If desired, a string expression can be substituted for *var$* (is enclosed in parenthesis).

***Example:***

```
ANIMAL$="pet",PET$="dog"
via ANIMAL$="cat"
print ANIMAL$," ",PET$;
end
```

When run, the result is pet cat.

## Format 2

***Assign to Composite Variable***

**VIA** *composite$,var_1$*\[\[,*subsc*\]\]*=expression*\[,...*n*\]

You can assign the value of the expression to a variable in a composite string. In this format, you can specify up to three subscripts for the variable(s).

***Example:***

```
0010 iolist X$,Y$,Z$
0020 dim PET$:iol=0010
0030 let X$="Dogs",Y$="Cats",Z$="!" rem Assign values to variables
0040 via PET$,"X$"="Lotsa",PET$,"Y$"="and",PET$,"Z$"="It's raining"
0050 print PET.X$," ",X$," ",PET.Y$," ",Y$
0060 let PET.X$=X$,PET.Y$=Y$
0070 print PET.Z$," ",PET.Y$," and ",PET.X$,Z$

->run
Lotsa Dogs and Cats
It's raining Cats and Dogs!
```
