I've defined two arrays in a Module called PubVars
I'm trying to merge the two arrays in my main form using the ArrayMerge sub in the manner below:
and run into this error "Only user-defined type defined in public object modules can be coerced to or from a variant.....".
How best can I merge these arrays?
This sub I got off the web and am posting for reference below:
Code:
Public Type LinesRec CORRECT As Integer QUESTION As String PROC As Integer PAY As Integer End Type Public Lines_Array() As LinesRec Public Type HeaderRec CORRECT As Integer QUESTION As String PROC As Integer PAY As Integer End Type Public Hdr_Array() As HeaderRec
Code:
ArrayMerge Hdr_Array, Lines_Array
How best can I merge these arrays?
This sub I got off the web and am posting for reference below:
Code:
Public Sub ArrayMerge(SourceArray As Variant, _ DestArray As Variant, Optional KillSource As Boolean = False) 'MERGES TWO ARRAYS 'SourceArray is appended to end of DestArray 'If KillSource is set to true, then SourceArray 'is erased following the merge 'EXAMPLE 'Dim i(2) As Integer 'Dim j() As Integer 'Dim iCtr As Integer ' 'ReDim j(2) As Integer 'i(0) = 4 'i(1) = 5 'i(2) = 6 'j(0) = 1 'j(1) = 2 'j(2) = 3 'ArrayMerge i, j ' 'For iCtr = 0 To UBound(j) ' Debug.Print j(iCtr) 'Outputs 1 2 3 4 5 6 'Next Dim l As Long, lngPos As Long, lngTemp As Long Dim lngUboundSource As Long Dim lngLBoundSource As Long Dim lngUboundDest As Long If (Not IsArray(SourceArray)) Or (Not IsArray(DestArray)) _ Then Exit Sub lngLBoundSource = LBound(SourceArray) lngUboundSource = UBound(SourceArray) lngUboundDest = UBound(DestArray) lngTemp = lngUboundSource - lngLBoundSource + 1 lngPos = UBound(DestArray) + 1 ReDim Preserve DestArray(LBound(DestArray) To _ UBound(DestArray) + lngTemp) For l = lngUboundDest To lngPos Step -1 DestArray(l + lngTemp) = DestArray(l) Next lngUboundSource = lngPos + lngTemp - 1 For l = lngPos To lngUboundSource DestArray(l) = SourceArray(l - lngPos) Next If KillSource = True Then Erase SourceArray End Sub
Comment