the project below gives the output that you describe but there are some remarks:
- is the second array always the complete array with all values?
- is the first array always smaller and missing some values?
- does the first array just miss values, or can there also be values which are different from the second array?
- can the second array also miss values while the first array also misses values on different indices?
- if the second array is always the complete one, why don't you just use the second array?
play around with the code below with all kinds of values and missing items to see if it still gives the desired results
'1 form with:
' 1 command button: name=Command1
Option Explicit
Private Sub Command1_Click()
Dim intFirst(4) As Integer
Dim intSecond(5) As Integer
Dim intDiff() As Integer
Dim intCombo() As Integer
'fill first array with example values
intFirst(0) = 10
intFirst(1) = 45
intFirst(2) = 3
intFirst(3) = 0
intFirst(4) = 89
'fill second array with example values
intSecond(0) = 10
intSecond(1) = 45
intSecond(2) = 22
intSecond(3) = 3
intSecond(4) = 0
intSecond(5) = 89
'compare arrays
intDiff = CompareArrays(intFirst, intSecond)
'combine arrays
intCombo = CombineArrays(intFirst, intSecond)
'print the arrays
Print "First"
PrintArray intFirst
Print "Second"
PrintArray intSecond
Print "Difference"
PrintArray intDiff
Print "Combination"
PrintArray intCombo
End Sub
Private Function CompareArrays(intFirst() As Integer, intSecond() As Integer) As Integer()
Dim intDiff() As Integer
Dim intUbound As Integer
Dim intIndex As Integer
Dim intSkip As Integer
intUbound = UBound(intSecond)
'make sure the second array has the highest ubound
If UBound(intFirst) > intUbound Then
'call function with array with highest ubound as second argument
intDiff = CompareArrays(intSecond, intFirst)
Else
'resize intDiff to the same size as intSecond
ReDim intDiff(intUbound) As Integer
intSkip = 0
'compare each item in the arrays
For intIndex = 0 To intUbound
If intFirst(intIndex - intSkip) = intSecond(intIndex) Then
intDiff(intIndex) = 0
Else
intDiff(intIndex) = intSecond(intIndex)
intSkip = intSkip + 1
End If
Next intIndex
End If
CompareArrays = intDiff
End Function
Private Function CombineArrays(intFirst() As Integer, intSecond() As Integer) As Integer()
Dim intCombo() As Integer
Dim intUbound As Integer
Dim intIndex As Integer
Dim intSkip As Integer
intUbound = UBound(intSecond)
'make sure the second array has the highest ubound
If UBound(intFirst) > intUbound Then
'call function with array with highest ubound as second argument
intCombo = CombineArrays(intSecond, intFirst)
Else
'resize intDiff to the same size as intSecond
ReDim intCombo(intUbound) As Integer
intSkip = 0
'compare each item in the arrays
For intIndex = 0 To intUbound
If intFirst(intIndex - intSkip) = intSecond(intIndex) Then
intCombo(intIndex) = intSecond(intIndex)
Else
intCombo(intIndex) = intSecond(intIndex)
intSkip = intSkip + 1
End If
Next intIndex
End If
CombineArrays = intCombo
End Function
Private Sub PrintArray(intArray() As Integer)
Dim intIndex As Integer
For intIndex = 0 To UBound(intArray)
Print CStr(intArray(intIndex))
Next intIndex
End Sub
Private Sub Form_Load()
Height = 7200
End Sub
The functions CompareArray and CombineArray are quite alike, the output is just different in that CompareArray returns a 0 for missing values, while CombineArray substitutes the value from the second array if it is missing in the first array
[EDIT]
is there any structure or logical order in the values in the arrays?
example: what do you want to combined array to be if:
- First array is : 1,2,4,5
- Second array is : 1,2,3,5
Which of the optional results do you want the combined array to be (and why) :
- Option A : 1,2,4,3,5
- Option B : 1,2,3,4,5
Or with possible real values :
- First array is : 10,27,13,12
- Second array is : 10,27,45,12
Optional results :
- Option A : 10,27,13,45,12
- Option B : 10,27,45,13,12
Can there be more than 1 subsequent holes ? For example 1,2,3,6 (missing 4 and 5)
Can there be values which are the same at different array items in the same array ? For example 12,27,31,31,43,58 or 12,27,31,43,31,58
What causes the missing values ? Can you add an ID to the values, so that you can determine the order and which items are missings ?