Skip to main content

Set

Assigns an object reference to a variable or property.

Synopsis

Set objectvar = objectexpression 

Arguments

objectvar Name of the variable or property; follows standard variable-naming conventions.
objectexpression Expression consisting of the name of an object, another declared variable of the same object type, or a function or method that returns an object of the same object type.

Description

The Set statement is used to assign a value to a variable. This value can be a number, a string, or an object reference. The variable can be a local variable, a process-private global variable, or a global variable, and can be subscripted. For further details on types of variables, see Identifiers and Variables in Using Caché Basic.

Generally, when you use Set to assign an object reference to a variable, no copy of the object is created for that variable. Instead, a reference to the object is created. More than one object variable can refer to the same object. Because these variables are references to (rather than copies of) the object, any change in the object is reflected in all variables that refer to it.

Examples

The following example shows two Set statements assigning a string to a variable. The second Set statement uses the concatenation operator to construct the string:

Set a = "the quick brown fox"
Println a
Set b = "the "&"quick "&"brown "&"fox"
Println b

The following example shows two Set statements that assign a string to a subscripted global variable:

Set ^a(1)="fruit"
Set ^a(1,1)="apple"
Println "An ",^a(1,1)," is a ",^a(1)

The following example shows how to assign an object reference to a variable:

Set person = New User.Person()
Println person

See Also

  • Basic: Dim Statement

  • ObjectScript: SET command

FeedbackOpens in a new tab