Skip to content

Tools - Array Tools ​

cToolsArray - Array Operation Tools ​

Overview ​

Provides practical methods for array operations, including removing elements, array extension, slicing, destructuring, etc.

Methods ​

Remove ​

Removes element at specified index from array, subsequent elements move forward automatically.

vb
Public Function Remove(ByRef Arr As Variant, ByVal Index As Integer) As Boolean

Parameters:

ParameterTypeDescription
ArrVariantArray to operate on (ByRef passed)
IndexIntegerIndex of element to remove

Return Value:

  • True - Removal successful
  • False - Removal failed (array empty or index out of bounds)

Example:

vb
Dim Arr As Variant
Arr = Array("a", "b", "c", "d")

' Remove element at index 1 ("b")
VBMAN.ToolsArray.Remove Arr, 1

' Result: Arr = ["a", "c", "d"]
Debug.Print Join(Arr, ",")  ' Output: a,c,d

extend ​

Extends values from source array to target array.

vb
Public Property Let extend(Vars As Variant, Value As Variant)

Example:

vb
Dim Target(0 To 2) As String
Dim Source As Variant
Source = Split("x/y/z", "/")

' Assign Source values to Target
VBMAN.ToolsArray.extend(Target) = Source

Debug.Print Target(0)  ' Output: x

DeArray ​

Destructures array to variables (assigns array elements to multiple variables).

vb
Public Sub DeArray(Arr As Variant, ParamArray OutVars())

Parameters:

ParameterTypeDescription
ArrVariantSource array
OutVarsParamArrayOutput variable array

Example:

vb
Dim A As String, C As String

' Assign array element 0 to A, element 2 to C
VBMAN.ToolsArray.DeArray Split("a/b/c", "/"), A, , C

Debug.Print A  ' Output: a
Debug.Print C  ' Output: c

IsArrayEmpty ​

Checks if array is empty.

vb
Public Function IsArrayEmpty(Arr As Variant) As Boolean

Return Value:

  • True - Array is empty
  • False - Array is not empty

Example:

vb
Dim EmptyArr() As Variant
Dim Arr As Variant
Arr = Array("a", "b")

Debug.Print VBMAN.ToolsArray.IsArrayEmpty(EmptyArr)  ' Output: True
Debug.Print VBMAN.ToolsArray.IsArrayEmpty(Arr)       ' Output: False

GetIndexByValue ​

Finds index of value in array.

vb
Public Function GetIndexByValue(Arr As Variant, Value As String) As Long

Parameters:

ParameterTypeDescription
ArrVariantArray to search
ValueStringValue to find

Return Value:

  • Returns index if found (0-based)
  • Returns -1 if not found

Example:

vb
Dim Arr As Variant
Arr = Array("apple", "banana", "cherry")

Dim Index As Long
Index = VBMAN.ToolsArray.GetIndexByValue(Arr, "banana")
Debug.Print Index  ' Output: 1

IsControlArray ​

Checks if control is a control array.

vb
Public Function IsControlArray(Ctl As Object) As Boolean

Example:

vb
' Check if Command1 is a control array
If VBMAN.ToolsArray.IsControlArray(Command1) Then
    Debug.Print "Command1 is a control array"
End If

Array Slice Functions ​

SliceByteArray ​

Processes Byte array slicing.

vb
Function SliceByteArray(ByRef Arr() As Byte, ByVal StartPos As Long, Optional ByVal EndPos As Long = -1) As Byte()

Parameters:

ParameterTypeDescription
ArrByte()Source byte array
StartPosLongStart position (0-based)
EndPosLongEnd position (0-based), -1 means to end

Example:

vb
Dim ByteArray() As Byte
Dim Sliced() As Byte

ByteArray = StrConv("Hello-World", vbFromUnicode)
Sliced = VBMAN.ToolsArray.SliceByteArray(ByteArray, 0, 4)

' Output slice result
Dim i As Long
For i = LBound(Sliced) To UBound(Sliced)
    Debug.Print Chr(Sliced(i));  ' Output: Hello
Next i

SliceString ​

Processes String type slicing.

vb
Function SliceString(ByVal Arr As String, ByVal StartPos As Long, Optional ByVal EndPos As Long = -1) As String

Example:

vb
Dim str As String
Dim sliced As String

str = "Hello World"
sliced = VBMAN.ToolsArray.SliceString(str, 0, 4)

Debug.Print sliced  ' Output: Hello

SliceLongArray ​

Processes Long type array slicing.

vb
Function SliceLongArray(ByRef Arr() As Long, ByVal StartPos As Long, Optional ByVal EndPos As Long = -1) As Long()

Example:

vb
Dim LongArr() As Long
Dim Sliced() As Long

LongArr = Array(10, 20, 30, 40, 50, 60, 70)
Sliced = VBMAN.ToolsArray.SliceLongArray(LongArr, 2, 5)

' Output: 30, 40, 50, 60

Byte Array Operation Functions ​

StringToByteArray ​

Converts string to byte array.

vb
Public Function StringToByteArray(ByVal St As String) As Byte()

Example:

vb
Dim Bytes() As Byte
Bytes = VBMAN.ToolsArray.StringToByteArray("Hello")

GetArrayLength ​

Gets array length.

vb
Public Function GetArrayLength(Arr() As Variant) As Long

Example:

vb
Dim Arr As Variant
Arr = Array("a", "b", "c")
Debug.Print VBMAN.ToolsArray.GetArrayLength(Arr)  ' Output: 3

FindByteArray ​

Finds position of keyword byte array in byte array.

vb
Public Function FindByteArray(ByRef Arr() As Byte, ByRef Keyword() As Byte) As Long

Return Value:

  • Returns start position if found (0-based)
  • Returns -1 if not found

Example:

vb
Dim Data() As Byte
Dim Keyword() As Byte

Data = StrConv("Hello World, Hello VB", vbFromUnicode)
Keyword = StrConv("World", vbFromUnicode)

Dim Pos As Long
Pos = VBMAN.ToolsArray.FindByteArray(Data, Keyword)
Debug.Print Pos  ' Output: 6

SplitByteArray ​

Splits byte array into two arrays.

vb
Public Function SplitByteArray(ByRef Arr() As Byte, ByVal Position As Long, Optional Offset As Long) As Variant

Return Value:

Returns Variant array containing two byte arrays:

  • Index 0: First part
  • Index 1: Second part (starting from Position + Offset)

Example:

vb
Dim Data() As Byte
Dim Result As Variant

Data = StrConv("HelloWorldVB", vbFromUnicode)
Result = VBMAN.ToolsArray.SplitByteArray(Data, 5, 0)

' Result(0) = "Hello"
' Result(1) = "WorldVB"

SplitByteArrayByKeyword ​

Splits byte array by keyword, supports multiple splits.

vb
Function SplitByteArrayByKeyword(ByRef ByteArray() As Byte, ByVal Keyword As Variant, Optional ByVal SplitCount As Long) As Variant

Parameters:

ParameterTypeDescription
ByteArrayByte()Byte array to split
KeywordVariantKeyword (supports string or byte array)
SplitCountLongSplit count, 0 means split all

Return Value:

Returns Variant array, each element is a byte array.

Example:

vb
Dim ByteArray() As Byte
Dim Keyword As String
Dim Result As Variant
Dim i As Long

ByteArray = StrConv("Hello World, This is a test. Hello World again!", vbFromUnicode)
Keyword = "World"

Result = VBMAN.ToolsArray.SplitByteArrayByKeyword(ByteArray, Keyword)

For i = LBound(Result) To UBound(Result)
    Debug.Print "Part " & (i + 1) & ": " & StrConv(Result(i), vbUnicode)
Next i

cToolsList - Recordset Conversion Tools ​

Overview ​

Provides conversion functionality between ADODB.Recordset and Collection/Dictionary.

Methods ​

RsToCollection ​

Converts ADODB.Recordset to cCollection (dictionary array).

vb
Public Function RsToCollection(Obj As Variant) As cCollection

Parameters:

ParameterTypeDescription
ObjVariantADODB.Recordset object

Return Value:

Returns cCollection, where each element is a Dictionary representing one record.

Example:

vb
Dim Rs As New ADODB.Recordset
Dim Coll As cCollection
Dim Row As Dictionary

' Execute query
Set Rs = Db.Execute("SELECT * FROM Users")

' Convert to collection
Set Coll = VBMAN.ToolsList.RsToCollection(Rs)

' Iterate results
Dim i As Long
For i = 1 To Coll.Count
    Set Row = Coll(i)
    Debug.Print Row("UserName") & " - " & Row("Email")
Next i

Description:

  • Supports pagination (preserves original recordset's pagination state)
  • Supports filters (preserves original recordset's Filter)
  • Clones recordset for iteration, does not affect original recordset position

VB6 and LOGO copyright of Microsoft Corporation