Wiki source for KeyPgOpLetlist


Show raw source

{{fbdoc item="title" value="Operator LET() (Assignment)"}}----
Assigns fields of a user defined type to a list of variables

{{fbdoc item="syntax"}}##
**Let**( //variable1// [, //variable2// [, ... ]] ) = //UDT_var//
##//or//##
**Let**( //variable1// [, //variable2// [, ... ]] ) => //UDT_var//
##
{{fbdoc item="param"}}
##//variable1// [, //variable2// [, ... ]]##
Comma separated list of variables to receive the values of the ##//UDT//## variable's fields.
##//UDT_var//##
A user defined type variable.

{{fbdoc item="desc"}}
Assigns the values from the ##//UDT_var//## variable's fields to the list of variables.

When the ##//UDT//## ##[[KeyPgExtends|Extends]]## a Base, the first variable (##//variable1//##) assigned by the operator then corresponds to a Base instance (only the other variables are those to receive the values of the data fields of the ##//UDT//##).

Union is not supported.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/operator/let-list.bas"}}%%(freebasic)
Type Vector3D
x As Double
y As Double
z as Double
End Type

Dim a As Vector3D = ( 5, 7, 9 )

Dim x As Double, y As Double

'' Get the first two fields only
Let( x, y ) = a

Print "x = "; x
Print "y = "; y
%%
Output:
%%
x = 5
y = 7
%%

{{fbdoc item="filename" value="examples/manual/operator/let-list2.bas"}}%%(freebasic)
Type Parent
Dim As Integer p1, p2
End Type

Type Child Extends Parent
Dim As Integer c1, c2
End Type

Type GrandChild Extends Child
Dim As Integer gc1, gc2
End Type

Dim As GrandChild gc = Type(1, 2, 3, 4, 5, 6)

Dim As Integer i1, i2
Dim As Integer j1, j2
Dim As Parent p
Dim As Child c

Let(c, i1, i2) = gc
Print c.p1, c.p2, c.c1, c.c2, i1, i2

Let(p, j1, j2) = gc
Print p.p1, p.p2, j1, j2
%%
Output:
%%
1 2 3 4 5 6
1 2 5 6
%%

{{fbdoc item="lang"}}
- Only available in the //[[CompilerOptlang|-lang fb]]// dialect.

{{fbdoc item="diff"}}
- New to ""FreeBASIC""

{{fbdoc item="see"}}
- ##[[KeyPgLet|Let]]##
- ##{{fbdoc item="keyword" value="KeyPgOpAssignment|Operator =[>] (Assignment)"}}##
- ##[[KeyPgOpLet|Operator Let (Assignment)]]##

{{fbdoc item="back" value="CatPgOpAssignment|Assignment Operators"}}{{fbdoc item="back" value="CatPgOperators|Operators"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode