exchange

Prev Next

Function Names

exchange

Description

This function exchanges the contents betweeen two variables, one variable and one entry in the table, or between two table entries. Note: Regarding variables, only the value in the base variable will be exchanged. Member variables will not be touched

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

2

Parameters

No.TypeDescription
1
io
all types Variable or table entry 1

2
io
all types Variable or table entry 2

Examples

       a[] = Abel; a[Age] = 30;
       b[] = Beata; b[Age] = 31;

       exchange( a[], b[] );

       echo( "Using exchange(...): Only base variables are exchanged.");
       echo( "  a[]: ", a[], ", ", a[Age] );
       echo( "  b[]: ", b[], ", ", b[Age] );

       table initialize( t, { { Name, Age}, {Corinne, 32} } );

       exchange( a[],    [t:Name,1] );
       exchange( a[Age], [t:Age,1] );

       echo( new line, "Exchanged with table entry: ");
       echo( "table: ", [t:Name,1] );
       echo( "  a[]: ", a[], ", ", a[Age] );

       // In case you want to exchange base variables with their members, use transactions.

       a[] = Abel; a[Age] = 30;
       b[] = Beata; b[Age] = 31;

       a[] <=> b[];

       echo( new line, "Using transactions: Members are also exchanged");
       echo( "  a[]: ", a[], ", ", a[Age] );
       echo( "  b[]: ", b[], ", ", b[Age] );

Output

Using exchange(...): Only base variables are exchanged.
  a[]: Beata, 30
  b[]: Abel, 31

Exchanged with table entry:
table: Beata
  a[]: Corinne, 32

Using transactions: Members are also exchanged
  a[]: Beata, 31
  b[]: Abel, 30
Try it yourself: Open LIB_Function_exchange.b4p in B4P_Examples.zip. Decompress before use.

See also

Transactions
<=>