Click or drag to resize

VarPut Function

Assign a value to a field or a memory variable of a given name.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.10
Syntax
 FUNCTION VarPut(
	cVarName AS STRING,
	uValue AS USUAL
) AS USUAL
View Source

Parameters

cVarName
Type: String
The name of the variable you want to create.
uValue
Type: Usual
The value to assign to the variable.

Return Value

Type: Usual
The value assigned to (uValue).
Remarks
If a field or memory variable called <cVarName> does not exist, a memory variable called <cVarName> is created.  Therefore, VarPut(), like MemVarPut(), can be used to create undeclared memory variables.  It should be used instead of a macro.
Remarks
Tip Tip
Dynamic memory variables (PUBLIC, PRIVATE, PARAMETERS) are supported in the X# language and runtime for compatibility only.
In most cases the type can and should be replaced with lexically scoped variables, such as LOCALs and GLOBALs.
Examples
This example uses VarPut() to store a value into a database field:
X#
LOCAL cFieldName
cFieldName := "Address"
VarPut(cFieldName, "Hollywood, Room 222")
This example uses VarPut() to create a memory variable:
X#
LOCAL cHasName
cHasName := "cPrivate"
// Instead of &cHasName := "new", use this:
VarPut(cHasName, "new")
? cPrivate                                        // new
This example shows that the newly created variable is a MEMVAR:
X#
VarPut("cVar", "hi")
? _MEMVAR->cVar                        // hi
See Also