JasonEnsor
Programmer
Hi Guys,
I am building a form in Excel that has 2 textboxes that hold values separated by ";". What I am wanting is to read each of the textbox values and store them as arrays, then to combine them in to a 3rd array whilst removing duplicates. What I have so far doesn't seem to work for creating the combined array.
So the function I am using is:
I am then testing this by using the following code
selectedClosureReasonsTxt.Text currently has "ABR;ACS;"
selectedRecallReasonsTxt.Text currently has "ABR;DIS;"
When I run the code my output is:
1 ACS
2
3 DIS
4
Which to me seems as though it is not reading the data in the first element in the Array. Does anyone have any ideas how to resolve this? Or can propose a better solution so that I end up with a final list of unique values from both textboxes in an array
Many Thanks in advance
Regards
J.
I am building a form in Excel that has 2 textboxes that hold values separated by ";". What I am wanting is to read each of the textbox values and store them as arrays, then to combine them in to a 3rd array whilst removing duplicates. What I have so far doesn't seem to work for creating the combined array.
So the function I am using is:
Code:
Function MergeArrays(vFirstArray As Variant, vSecondArray As Variant) As Variant
Dim vMergedArray() As Variant
Dim iFirstArrayLen As Integer
Dim iSecondArrayLen As Integer
Dim iMergedArrayLength As Integer
Dim iCounter As Integer
iFirstArrayLen = UBound(vFirstArray)
iSecondArrayLen = UBound(vSecondArray)
iMergedArrayLength = iFirstArrayLen + iSecondArrayLen
ReDim vMergedArray(0 To iMergedArrayLength)
iCounter = 1
Do While iCounter <= iFirstArrayLen
vMergedArray(iCounter) = vFirstArray(iCounter)
iCounter = iCounter + 1
Loop
Do While iCounter <= iMergedArrayLength
vMergedArray(iCounter) = vSecondArray(iCounter - iFirstArrayLen)
iCounter = iCounter + 1
Loop
MergeArrays = vMergedArray
End Function
I am then testing this by using the following code
Code:
Option Base 1
Private Sub Image1_Click()
Dim vFirstArray As Variant
Dim vSecondArray As Variant
Dim vArray3 As Variant
vFirstArray = Split(selectedClosureReasonsTxt.Text, ";")
vSecondArray = Split(selectedRecallReasonsTxt.Text, ";")
vArray3 = MergeArrays(vFirstArray, vSecondArray)
Dim iCounter As Integer
For iCounter = 1 To UBound(vArray3)
Debug.Print iCounter & " " & vArray3(iCounter)
Next iCounter
End Sub
selectedClosureReasonsTxt.Text currently has "ABR;ACS;"
selectedRecallReasonsTxt.Text currently has "ABR;DIS;"
When I run the code my output is:
1 ACS
2
3 DIS
4
Which to me seems as though it is not reading the data in the first element in the Array. Does anyone have any ideas how to resolve this? Or can propose a better solution so that I end up with a final list of unique values from both textboxes in an array
Many Thanks in advance
Regards
J.