Previous SectionConstants
Document HomeContents
OperatorsNext Section

Variables

OVM currently supports three basic variable types. These are integer, boolean, and string. The string type comes in two flavours the 2nd of which will be discussed in the Session Variables section.

The most important concept to remember is that all variables must be defined before they are used. As each variable is defined the OVM compiler allocates storage space for it in the compiled version of the OVM script file.

Variable Names

OVM variable names can contain the following characters : a - z, A - Z, _, 0 - 9.

Each variable must start with a letter or an underscore, and can be up to 30 characters long. Any characters after this will be discarded, and a compiler warning will be issued to that effect.

Note that if two or more similar names are truncated back to 30 characters the OVM compiler may not be able to properly distinguish between them.

Variable names are not case sensitive so a variable named a1 can be referenced by both a1, and A1.

Examples of valid variable names are : a, a1, _, _1, iamavariable, iamavariablenamethatiswaytoolongandiwillbetruncatedbackto30characters.

Examples of invalid variable names are : 1a, a$, no whitespace allowed.

Integer Variables

Integer variables are defined in OVM through the use of the @integer command and are used to store signed integers (Ie whole numbers).

@integer fred               ! define integer variable fred
@set fred = 10              ! set fred equal to decimal 10
@comment("fred = ",fred)    ! display fred's value

@integer mary, jane         ! define two more integer variables
@set mary = 20              ! give mary a value
@jane = -5                  ! give jane a value
@fred = mary + jane         ! do some simple arithmetic
@comment("fred = ",fred)    ! display fred's value

Integer variables can be either explicity set to an integer literal or constant, or they can be set to the result of an integer expression.

The range of integers that an OVM integer can contain is system dependent but should never be less than -2147483648 to 2147483647 (-$80000000 to $7FFFFFFF hex). This corresponds to 32 bits per integer. Ie -2^31 to 2^31 - 1 stored as 2’s complement.

The OVM compiler always assigns the value 0 to an integer variable at compile time unless overridden with the defaultvalue keyword.

Each integer variable defined will add at least 4 bytes to the compiled OVM script file.

Boolean Variables

Boolean variables are defined in OVM through the use of the @boolean command and are used to store the logical values TRUE or FALSE (ON or OFF).

Each boolean variable can either be in the TRUE state, or in the FALSE state.

@boolean canfredgetmarried ! define a boolean variable
@integer fred = 20         ! define fred and make him 20

@if fred >= 18 then
    @set canfredgetmarried = true
@else
    @set canfredgetmarried = false

@if canfredgetmarried then
    @comment("Fred is old enough to get married")
@else
    @comment("Sorry Fred - maybe next year")

Boolean variables can either be set explicitly to true or false, on or off, or they can be set to the result of a boolean expression. The above example could also have been written as :

@boolean canfredgetmarried  ! define a boolean variable
@integer fred = 20          ! define fred and make him 20

@set canfredgetmarried = fred >= 18   ! is fred old enough ?

@if canfredgetmarried then
    @comment("Fred is old enough to get married")
@else
    @comment("Sorry Fred - maybe next year")

Although internally OVM treats booleans similarly to integers you cannot assign an integer value to a boolean, or a boolean value to an integer.

@boolean fred = 1            ! won't compile - syntax error
@integer mary = true         ! won't compile - syntax error

@boolean fred = 20 > 10      ! ok - fred set to true
@if fred then                ! check fred using an if statement
    @set mary = 1            ! and set mary as appropriate
@else
    @set mary = 0

The OVM compiler always assigns the value false to a boolean variable at compile time unless overridden with the defaultvalue keyword.

Each boolean variable defined will add at least 4 bytes to the compiled OVM script file.

String Variables

String variables are defined in OVM through the use of the @string command and are used to store text strings, and as buffers to hold text information for some commands. Each string variable can hold up to 255 characters.

@string destination									! Where are we travelling to
@string country             ! The country it is in

@input(destination,"Where are you going to visit ?")

@comment("Since you are going to ",destination,".")

@if destination = "Hawaii" then
    @comment("Don't forget your surfboard.")
@else if destination = "The Alps" then
    @comment("Don't forget you skis.")
@else if destination = 'Melbourne' then
    @comment("Don't forget your umbrella.")
@else
    @comment("Send me a postcard with a picture of ",destination)

@if inset(destination,"Hawaii","California") then
    @country = "United " + "States " + "of " + "America"
@else if inset(destination,"Brisbane","Sydney","Melbourne") then
    @country = "Australia"
@else
    @country = ""

@if country <> "" then
    @comment("I have always wanted to visit ",country)
@else
    @comment("Which country is ",destination," in?")

String variables can either be explicity set, or can be set to the result of a string expression.

Some OVM commands require the name of a string variable to use as a place to store information to.

The OVM compiler always assigns the value "" (the empty string) to a string variable at compile time unless overridden with the defaultvalue keyword.

Strings in OVM can store ASCII 0.

Strings can hold a maximum of 255 characters.

Each string variable defined will add at least 260 bytes to the size of the compiled OVM script file.

Date Strings

Date/Time STRINGS returned from other functions, such as GETDATE or GETDATETIME, and used as parameters of date manipulation functions, such as ADVANCE and REGRESS, have one of the following formats:

NB Year cannot be any greater than 100 years before or after current date

Code Definition
YYYY Year as 1900–9999
YY Year as 00–99
If greater than 29 it will be treated as 20th century date (i.e. 19YY).
If less than or equal to 29 it will be treated as a 21st century date (i.e. 20YY)
MM Month as 01–12
DD Day as 1–31
hh Hour as 00–23
mm Minute as 00–59
ss Second as 00–59
xxx Millisecond as 000-999
dow Day of the week as Sun–Sat

Variable Subsitution – The use of {} in Implicit Host Command Lines

When curly brackets are used in implicit host command lines they no longer refer to a session variable but instead to the contents of previously defined ordinary variable. OVM calls this variable substitution and provides it for greater backwards compatibility with Ozterm.

! The following demonstrates a variable substitution for an
! implicit host command which will enter the commands
! "date, sleep 10, date" into a Unix host.

@mode("UNIX")
@connect() 
@string c1 = `date\r`, c2 = `sleep 10\r`
{c1}{c2}{c1}

Note that in the above implicit host command line the values of the previously defined variables c1, and c2 are sent to the connected host. This is not the same as the following example.

! The following is not a variable substitution. 
@hostcmd({c1}, {c2}, {c1}) ! this is not a variable substitution

In this case the curly brackets refer to non-existent session variables `date\r`, and `sleep 10\r` which will cause an error at runtime when the line is executed because they do not exist.

@hostcmd(c1, c2, c1) ! this will work

Remember. Curly brackets in implicit host commands are variable substitutions while in normal command lines (including @hostcmd) they refer to session variables.

Arrays of variables

OVM directly supports arrays of variables of the 3 basic types (integer, boolean, string). Arrays in OVM are defined in a similar way to simple variables, and follow the same naming rules.

@integer timestable[10,1..10] ! 2 dimensional array of integers
@integer index1, index2 ! going to use these to index array 

@for index1 = 1 to 10
    @for index2 = 1 to 10
        @timestable[index1,index2] = index1 * index2

The size of each dimension must be defined using literals, or constant expressions.

@integer myarray[100]          ! fine

@constant integer size1 = 100  ! define a constant
@string anotherarray[size1]    ! also fine

@integer size2 = 100           ! define an integer
@boolean notgoingtowork[size2] ! syntax error - not a literal or constant

Each dimension can be specified by either just its number of elements (ie size) or by speicifying both the lower and upper bounds separated by "..".

@integer a1[10], a2[-5..5]

The maximum number of dimensions is internally limited to 10. It is not recommended to define very large arrays because they use correspondingly large amounts of memory both at compile time, and at runtime. Like simple variables, space is allocated for the array in the compiled OVM file. Be aware that creating very large arrays can quickly consume all available memory in your computer. The total number of array elements is determined by multiplying out the size of each dimension.

@integer bigarray[1,2,3,4,5,6,7,8,9,10] ! 3628800 elements !!!!

The size of each dimension must be at least 1. The size of a dimension when upper, and lower bounds are specified is upper – lower + 1. Unless lower, and upper bounds are explicitly defined dimension indicies are numbered from 1. Consider the following.

@integer fred[10]   ! creates 10 element array indexed 1 to 10
@integer foo[0..10] ! creates 11 element array indexed 0 to 11

An array, or one of its elements cannot be used in place of a simple variable in commands that require a simple variable.

Array indicies are bounds checked at runtime.

Array elements can only be initialised, and referenced individually. Arrays as a whole cannot be compared or assigned to each other.

@string country[5], capital[5]

@country[1] = "Australia"
@capital[1] = "Canberra"
! Note - unassigned string array elements will be blank
@country[5] = "USA"
@capital[5] = "Washington DC"

@for integer index = 1 to 5
    @comment("The capital of ",country[index], \
    " is ",capital[index])

At compile time the OVM compiler sets every element in the array to 0, false, or "" depending upon the type of the array.

At runtime you can clear every element in an array at once with the @clear command.

Arrays can be passed to user defined procedures and functions but they must always be passed by reference, never by value.

Using variables

When using variables remember :

A variable must be both defined and in scope before it can be used.

A variable can only be assigned the result of an expression that returns the same type as the variable itself.

A variable’s definition can be combined with an assignment but the assignment still takes place at runtime.

@integer fred ! define a variable
@set fred = 10 ! assign 10 to fred at runtime

can be replaced with

@integer fred = 10 ! assignment still happens at runtime

A value assigned to a variable in a combined definition / assignment is applied only if the line is reached at runtime, and is re-applied every time the line is reached (unless the defaultvalue keyword is used). For example.

@for integer fred = 1 to 10 ! do a loop 10 times
@begin
    @integer mary = 0        ! assigns 0 to mary every time
    @inc(mary)               ! add 1 to mary
    @comment("mary = ",mary) ! display value of mary
@end

Two or more variables can share the same name but only in different scopes. Also inner scope variables hide variables of an outer scope if they share the same name.

@integer fred = 10             ! define first fred as an integer

@begin
    @string fred = "Hello"     ! inner fred hides the outer fred
    @comment("fred = ",fred)   ! display fred = Hello
@end

@comment("fred = ",fred)       ! display fred = 10

Note that the operator = doubles both as the equal to operator, and as the assignment operator. There are no separate assignment or equality operators as in other languages such as C and Pascal.

@boolean fred = 20 > 10 ! fred will be set to true at runtime
@boolean mary = 20 = 10 ! mary will be set to false at runtime

Using the @set keyword is optional in OVM but is recommended for code clarity since it clearly identifies the that a runtime assignment is taking place.



Previous SectionConstants
Document HomeContents
OperatorsNext Section



This publication has been prepared and written by Telstra Corporation Limited (ACN 051 775 556), and is copyright. Other than for the purposes of and subject to the conditions prescribed under the Copyright Act, no part of it may in any form or by any means (electronic, mechanical, microcopying, photocopying, recording or otherwise) be reproduced, stored in a retrieval system or transmitted without prior written permission from the document controller. Product or company names are trademarks or registered trademarks of their respective holders.

Note for non-Telstra readers: The contents of this publication are subject to change without notice. All efforts have been made to ensure the accuracy of this publication. Notwithstanding, Telstra Corporation Limited does not assume responsibility for any errors nor for any consequences arising from any errors in this publication.