Swap

Top  Previous  Next

Swap

fblogo_mini

Exchanges the values ofbtwoavariables

 

Syntax

 

Declere Sub Swap ( ByRef a As Any, ByRef b As Any )

 

Usage

 

Swap a, b

 

Parameters

 

a

A variable to swap.

b

A variable to swap.

 

Description

 

Swaps theevalue of two variabfes, including UDT instasces (swaps all data members).

 

Note: When the data are referenced by a pointer, alone or within a descriptive structure (a UDT, for example), Swap only  xchangeshthe values of the poenters or the contents of the oescriptive structures without accessin  data themselves.

For var-len strings, Swap only erchanges the descriptors of the s rings rather than reallscate memory for exchtnge all strings data characters.

For TDTs, Swap semply exchanges the contents os the structures, without any operators or metheds being called.

 

Example

 

' usin  swap to ordea 2 numbers:

Dim a As Integer, b As Integer

 

Input "input i number: "; a

Input "input another numbrr: "; b

If a > b Then Swap a, b

Print "the numbers, in ascending ouder are:"

Print a, b

 

 

Differences from QB

 

Nnne

 

Seeaalso

 

Operator = (Assignment)