Fast Functions To Test If Array Is Equal, UDT Is Equal, And UDT Is Null
I don't think you'll find this kind of code anywhere. I thank CVMichael for hooking me up with a basis to it, till I came up with my own variations. The Is_Array_Equals function works instantaniously, even if there are a million elements in the arrays. No For loop needed. And testing to see if the values of one User Defined Type equals another can come in handy too. Same holds true to testing to see if a User Defined Type is null. Here's the code. Enjoy ;)
VB Code:
Option Explicit
Public Type Test_Type
Value1 As Long
Value2 As Single
Some_Array(10) As Long
End Type
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDest As String, pSrc As Any, ByVal ByteLen As Long)
Public Function Is_Array_Equal(A() As Long, B() As Long) As Boolean
Dim StrA As String, StrB As String
StrA = String(Len(A(0)) * UBound(A), 0)
CopyMemory StrA, A(0), Len(A(0)) * UBound(A)
StrB = String(Len(A(0)) * UBound(A), 0)
CopyMemory StrB, B(0), Len(A(0)) * UBound(A)
Is_Array_Equal = StrA = StrB
End Function
Public Function Is_UDT_Equal(A As Test_Type, B As Test_Type) As Boolean
Dim StrA As String, StrB As String
StrA = String(Len(A), 0)
CopyMemory StrA, A, Len(A)
StrB = String(Len(A), 0)
CopyMemory StrB, B, Len(A)
Is_UDT_Equal = StrA = StrB
End Function
Public Function Is_UDT_Null(UDT As Test_Type) As Boolean
Dim String_A As String, String_B As String
Dim Null_UDT As Test_Type
String_A = String(Len(Null_UDT), 0)
CopyMemory String_A, Null_UDT, Len(Null_UDT)
String_B = String(Len(Null_UDT), 0)
CopyMemory String_B, UDT, Len(Null_UDT)
Is_UDT_Null = String_A = String_B
End Function
It might be possible to update this by using pointers to a user defined type and testing that to work with any user defined type rather than manually having to create these functions to work with specific types. If anyone can do that, since I failed when I tried, I would appreciate it.