SWAP Syntax 1: exchanges the values or contents of two variables of the same data type. Syntax 2: exchanges, between two strings, substrings of a specified length located at specified positions.
Syntax 1:SWAP Variable1, Variable2 Parameters:
Syntax 2:SWAP (PBYTE) &StrOne[P1] AS STRING, (PBYTE) &StrTwo[P2] AS STRING, Length AS INTEGER) Parameters:
|
This example exchanges
4 characters, "1234", beginning at position 0 of a$
with
4 characters, "4321", beginning at position 6 of b$.
DIM a$ DIM aWas$ DIM b$ DIM bWas$ a$ = "1234567890" b$ = "0987654321" aWas$ = a$ bWas$ = b$ SWAP (PBYTE) &a$[0], (PBYTE) &b$[6], 4 PRINT "a$ before SWAP was ", aWas$ PRINT "a$ after SWAP is ", a$ PRINT PRINT "b$ before SWAP was ", bWas$ PRINT "b$ after SWAP is ", b$
a$ before SWAP was 1234567890 a$ after SWAP is 4321567890 b$ before SWAP was 0987654321 b$ after SWAP is 0987651234
The following statements are functionally equivalent. The first is verbose, the second is not but it might look more cryptic to some users.
SWAP CAST(PBYTE, ADDRESSOF Mut$[i]), CAST(PBYTE, ADDRESSOF Mut$[CAST(LONG, Range(i+1, L-1))]), 1 SWAP (PBYTE) &Mut$[i], (PBYTE)&Mut$[( LONG) Range(i + 1,L - 1)], 1