赋值
[ LET ] Destination = Expression
将
表达式的值赋给下列元素之一:
-
一个局部变量
-
一个函数参数
-
一个公共变量或者一个类变量
-
一个数组元素
-
一个对象公共变量
-
一个对象属性属性
许多有返回值的命令也可以使用赋值语法:
EXEC
、
NEW
、
OPEN
、
RAISE
、
SHELL
。
示例
iVal = 1972
Name = "[/def/gambas]"
hObject.Property = iVal
cCollection[sKey] = Name
...
Assignments of embedded structures or arrays
自从 3.17
If the assignment
Destination is actually a structure or an embedded array, then the contents of
Expression is recursively copied in the
Destination.
Of course,
Expression is first converted to the datatype of
Destination before the copy is done.
When an array is copied, if the source and the destination do not have the same number of elements, then the smallest number of elements is used to do the copy.
The copy is done only when the structure or the array are embedded. If not embedded, then structures and arrays are normal Gambas objects, and the assignment is just a reference copy.
Examples
Struct Person
FirstName As String
LastName As String
Age As Integer
BirthDate As Date
Height As Float
End Struct
Private $aPeople[16] As Struct Person
Private $hFirst As Struct Person
Private $aOther[4] As Struct Person
...
' Copy the 4th people into $hFirst
$hFirst = $aPeople[3]
' Copy the four first people into $aOther
$aOther = $aPeople
' Only the four first elements of $aPeople are modified
$aPeople = $aOther
参见