Help Center
Help CenterAfxNovaString Management

Array Macros

Members (10)

Documentation

Array Macros

Macros to manipulate one-dimensional dynamic arrays.

Include file: AfxNova/AfxArrays.inc.

NameDescription
AppendElementToArrayAppends a new element to the array.
AppendArrayToArrayAppends one array to another array.
InsertElementIntoArrayInserts a new element into an array.
InsertArrayIntoArrayInserts an array into another array.
RemoveElementFromArrayRemoves the specified element from an array.
RemoveFirstElementFromArrayRemoves the first element from an array.
RemoveLastElementFromArrayRemoves the last element from an array.
RemoveElementsFromArrayRemoves the specified elements from an array.

Sorting Macros

Include file: AfxNova/AfxSort.inc.

Note: Before including this file, add

#define _WIN32_WINNT &h0602
NameDescription
AfxSortNumericArraySorts one-dimensional numeric arrays of any type.
AfxSortStringArraySorts one-dimensional string arrays of any type.

AppendElementToArray

Appends a new element to a dynamic one-dimensional array.

#macro AppendElementToArray(rg, elem)
ParameterDescription
rgThe array.
elemThe element to append.
Remarks

The array and the element to append can be of any type, but they have to be of the same type between them.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage example
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
' Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

AppendArrayToArray

Appends a one-dimensional array to another dynamic one-dimensional array.

#macro AppendArrayToArray(rg, rg2)
ParameterDescription
rgThe array.
rg2The array to append.
Remarks

The array and the array to append can be of any type, but they have to be of the same type between them.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage examples
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM rg2(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
' Fill the array to append
xStr = "String 2 - "
FOR i AS LONG = 1 TO 5
   AppendElementToArray(rg2, xStr & WSTR(i))
NEXT
' // Append the array to the first array
AppendArrayToArray(rg, rg2)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT
Can also be used with numbers:
DIM rg(ANY) AS LONG
DIM rg2(ANY) AS LONG
' // Fill the array
DIM nLong AS LONG = 1
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, nLong)
   nLong += 1
NEXT
' Fill the array to insert
nLong = 12345
FOR i AS LONG = 1 TO 5
   AppendElementToArray(rg2, nLong)
   nLong += 1
NEXT
AppendArrayToArray(rg, rg2)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

InsertElementIntoArray

Inserts a new element before the specified position into a dynamic one-dimensional array.

#macro InsertElementIntoArray(rg, pos, elem)
ParameterDescription
rgThe array.
posThe position in the array where the new element will be added. This position is relative to the lower bound of the array.
elemThe element to insert.
Remarks

The array and the array to append can be of any type, but they have to be of the same type between them.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage examples
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
InsertElementIntoArray(rg, 5, xStr & WSTR(11))
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT
Can also be used with numbers:
DIM rg(ANY) AS LONG
DIM rg2(ANY) AS LONG
' // Fill the array
DIM nLong AS LONG = 1
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, nLong)
   nLong += 1
NEXT
' Fill the array to insert
nLong = 12345
FOR i AS LONG = 1 TO 5
   AppendElementToArray(rg2, nLong)
   nLong += 1
NEXT
InsertElementIntoArray(rg, 5, nLong)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

InsertArrayIntoArray

Inserts a one-dimensional array before the specified position in another dynamic one-dimensional array.

#macro InsertArrayIntoArray(rg, pos, rg2)
ParameterDescription
rgThe array.
posThe position in the array where the new element will be added. This position is relative to the lower bound of the array.
rg2The array to insert.
Remarks

The array and the array to insert can be of any type, but they have to be of the same type between them.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage examples
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM rg2(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
' Fill the array to insert
xStr = "String 2 - "
FOR i AS LONG = 1 TO 5
   AppendElementToArray(rg2, xStr & WSTR(i))
NEXT
' // Insert the array to the first array
InsertArrayIntoArray(rg, 5, rg2)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT
Can also be used with numbers:
DIM rg(ANY) AS LONG
DIM rg2(ANY) AS LONG
' // Fill the array
DIM nLong AS LONG = 1
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, nLong)
   nLong += 1
NEXT
' Fill the array to insert
nLong = 12345
FOR i AS LONG = 1 TO 5
   AppendElementToArray(rg2, nLong)
   nLong += 1
NEXT
' // Insert the array to the first array
InsertArrayIntoArray(rg, 5, rg2)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

RemoveElementFromArray

Removes the specified element of a dynamic one-dimensional array.

#macro RemoveElementFromArray(rg, pos)
ParameterDescription
rgThe array.
posThe position in the array of the element to remove. This position is relative to the lower bound of the array.
Remarks

The array can be of any type.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage examples
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
' // Remove the fifth element
RemoveElementFromArray(rg, 5)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT
Can also be used with numbers:
DIM rg(ANY) AS LONG
' // Fill the array
DIM nLong AS LONG = 1
FOR i AS LONG = 1 TO 10
   REDIM PRESERVE rg(UBOUND(rg) + 1)
   rg(i - 1) = nLong
   nLong += 1
NEXT
' // Remove the specified element
RemoveElementFromArray(rg, 5)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

RemoveFirstElementFromArray

Removes the first element of a dynamic one-dimensional array.

#macro RemoveFirstElementFromArray(rg)
ParameterDescription
rgThe array.
Remarks

The array can be of any type.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage examples
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
' // Remove the frst element
RemoveFirstElementFromArray(rg)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT
Can also be used with numbers:
DIM rg(ANY) AS LONG
' // Fill the array
DIM nLong AS LONG = 12345
FOR i AS LONG = 1 TO 10
   REDIM PRESERVE rg(UBOUND(rg) + 1)
   rg(i - 1) = nLong
   nLong += 1
NEXT
' // Remove the first element
RemoveFirstElementFromArray(rg)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

RemoveLastElementFromArray

Removes the last element of a dynamic one-dimensional array.

#macro RemoveLastElementFromArray(rg)
ParameterDescription
rgThe array.
Remarks

The array can be of any type.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage examples
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rg(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, xStr & WSTR(i))
NEXT
' // Remove the last element
RemoveLastElementFromArray(rg)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT
Can also be used with numbers:
DIM rg(ANY) AS LONG   ' // or DWORD, SINGLE, DOUBLE, etc.
' // Fill the array
DIM nLong AS LONG = 12345
FOR i AS LONG = 1 TO 10
   REDIM PRESERVE rg(UBOUND(rg) + 1)
   rg(i - 1) = nLong
   nLong += 1
NEXT
' // Remove the last element
RemoveLastElementFromArray(rg)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

RemoveElementsFromArray

Removes the specified elements of a dynamic one-dimensional array.

#macro RemoveElementsFromArray(rg, rgElements)
ParameterDescription
rgThe array.
rgElementsArray of long values indicating the 0-based positions of the elements to remove.
Remarks

The array can be of any type.

If the array has a fixed length, GetLastError will return an E_ACCESSDENIED error.

Usage example
DIM rg(ANY) AS LONG
' // Fill the array
DIM nLong AS LONG = 1
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rg, nLong)
   nLong += 1
NEXT
' Fill the array of elements to delete
DIM rgElements(0 TO 3) AS LONG => {2, 4, 6, 8}
RemoveElementsFromArray(rg, rgElements)
' // Display the array
FOR i AS LONG = LBOUND(rg) TO UBOUND(rg)
   print rg(i)
NEXT

AfxSortNumericArray

Sorts one-dimensional numeric array of any type. The macro detects the type of array and calls the appropriate sorting procedures.

#macro AfxSortNumericArray(rg, ascending)
ParameterDescription
rgThe array to sort.
ascendingIf true, sorts the array in ascending order. I false, sorts the array in descending order.
Return code

It does not return a result code.

Usage example
#define XNUMBER DOUBLE ' // or SHORT, INTEGER, LONG, LONGINT, etc.
DIM rgNum(ANY) AS XNUMBER
DIM rgNum2(ANY) AS XNUMBER
DIM xNum AS XNUMBER = 1234567.89
' // Fill the array
FOR i AS LONG = 1 TO 10
   xNum += 0.01
   AppendElementToArray(rgNum, xNum)
NEXT
' Fill the array to insert
xNum = 111.01
FOR i AS LONG = 1 TO 5
   xNum += 1
   AppendElementToArray(rgNum, xNum)
NEXT
' // Insert the array to the first array
InsertArrayIntoArray(rgNum, 5, rgNum2)
' // Display the array
FOR i AS LONG = LBOUND(rgNum) TO UBOUND(rgNum)
   print rgNum(i)
NEXT
' // Sort the numeric array
AfxSortNumericArray(rgNum, true)
' // Display the sorted array
FOR i AS LONG = LBOUND(rgNum) TO UBOUND(rgNum)
   print rgNum(i)
NEXT

AfxSortStringArray

Sorts one-dimensional string array of any type. The macro detects the type of array and calls the appropriate sorting procedures.

#macro AfxSortStringArray(rg, ascending)
ParameterDescription
rgThe array to sort.
ascendingIf true, sorts the array in ascending order. I false, sorts the array in descending order.
Return code

It does not return a result code.

Usage example
#define XSTRING DWSTRING ' // or STRING, BSTRING, etc.
DIM rgstr(ANY) AS XSTRING
DIM rgstr2(ANY) AS XSTRING
DIM xStr AS XSTRING = "String - "
' // Fill the array
FOR i AS LONG = 1 TO 10
   AppendElementToArray(rgstr, xStr & WSTR(i))
NEXT
' Fill the array to append
xStr = "String 2 - "
FOR i AS LONG = 1 TO 5
   AppendElementToArray(rgstr2, xStr & WSTR(i))
NEXT
' // Append the array to the first array
AppendArrayToArray(rgstr, rgstr2)
' // Display the array
FOR i AS LONG = LBOUND(rgstr) TO UBOUND(rgstr)
   print rgstr(i)
NEXT
' // Sort the array
AfxSortStringArray(rgstr, true)
' // Display the sorted array
FOR i AS LONG = LBOUND(rgstr) TO UBOUND(rgstr)
   print rgstr(i)
NEXT