Right gents I've been feverishly developing my natural language processing program and today, for the first time I encountered something that completely baffled me. I solved, but I had to use a very dirty solution, which is not ideal.
Perhaps some VB.NET expert can tell me what the hell is going on.
Below is my main subroutine, which calls the function (IsSimilarUserRecord) below it.
I haven't pasted all the code for IsSimilarUserRecord, as it is not important.
The parts I want you to take a look at are in bold (purple and pink)
main sub:
Public Sub CompileShortListOfSimilarUserRecordsMain(ByVal mainUserRecordID As String, ByVal clientID As Integer, ByRef shortListOfSimilarUserRecordIDs As ArrayList) 'Optional ByVal userRecordLineContents As String = "")
If String.IsNullOrEmpty(mainUserRecordID) Then
errorLog.Add("ERROR179: record id input is empty (" & mainUserRecordID & "). Unable to compile short lilst of similar user records.")
Exit Sub
End If
'we can't start a new short list until the previous short list has been completely emptied of user records
shortListOfSimilarUserRecordIDs.Clear()
shortListOfSimilarUserRecordIDs.Add("")
'now load up the fields of the main user record into an array list
Dim mainUserRecordFieldsArrayList As New ArrayList
mainUserRecordFieldsArrayList = userRecordArrayHandler.ReturnGenericFieldsInArrayList(mainUserRecordID)
mainUserRecordFieldsArrayList.Sort()
'now go through all the user records which apply to the current user
'load all the user record fields into arraylists, one by one.
Dim arrayProcessor As New ArrayProcessingClass
Dim localUserRecordIDAL As New ArrayList
localUserRecordIDAL = clientInfoHolder(clientID).GetUserRecordIDArrayList
Dim URIDIndexMax As Integer = localUserRecordIDAL.Count - 1
For URIDIndex = 1 To URIDIndexMax 'do for each user record loaded in memory
Dim tempURID As String = localUserRecordIDAL(URIDIndex).ToString
Dim tempURGenericFieldArrayList As New ArrayList
tempURGenericFieldArrayList = userRecordArrayHandler.ReturnGenericFieldsInArrayList(tempURID)
tempURGenericFieldArrayList.Sort()
Dim textProcessing As New TextProcessingClass
If arrayProcessor.ArrayListStringEquals(mainUserRecordFieldsArrayList, tempURGenericFieldArrayList) Then
'do nothing 'ignore the identical user record
ElseIf (IsSimilarUserRecord(mainUserRecordFieldsArrayList, tempURGenericFieldArrayList)) Then 'check if user record array is similar to new user record
'if it is we add the user record id to the short list
shortListOfSimilarUserRecordIDs.Add(tempURID)
End If
Next URIDIndex
'if none found
If shortListOfSimilarUserRecordIDs.Count < 2 Then 'count = 0 or 1
shortListOfSimilarUserRecordIDs.Clear()
End If
End Sub
Public Function IsSimilarUserRecord(ByVal arraylist1 As ArrayList, ByVal arraylist2 As ArrayList, Optional ByVal allowableNumberOfElementsToBeNonIdentical As Integer = 1) As Boolean
'stuff
End Function
Now what is happening is that in the purple line I am calling IsSimilarUserRecord. All arguments are passed, Byval (not Byref). When I call IsSimilarUserRecord for the first time, mainUserRecordFieldsArrayList and tempURGenericFieldArrayList are passed into IsSimilarUserRecord without a problem. However, when IsSimilarUserRecord returns its boolean value, the 2 array lists: mainUserRecordFieldsArrayList and tempURGenericFieldArrayList are both emptied of their contents. This should not be happening, as their contents were passed ByVal, so should be unaltered after the boolean value is returned.
In itself this wouldn't be a problem but because the contents of mainUserRecordFieldsArrayList have to be repeatedly used (as it is contained in a For loop), after the 1st loop, that array list is useless.
Can somebody explain to me why the array lists are getting emptied, whenever I call IsSimilarUserRecord and pass the 2 array to it?
Thanks
Perhaps some VB.NET expert can tell me what the hell is going on.
Below is my main subroutine, which calls the function (IsSimilarUserRecord) below it.
I haven't pasted all the code for IsSimilarUserRecord, as it is not important.
The parts I want you to take a look at are in bold (purple and pink)
main sub:
Public Sub CompileShortListOfSimilarUserRecordsMain(ByVal mainUserRecordID As String, ByVal clientID As Integer, ByRef shortListOfSimilarUserRecordIDs As ArrayList) 'Optional ByVal userRecordLineContents As String = "")
If String.IsNullOrEmpty(mainUserRecordID) Then
errorLog.Add("ERROR179: record id input is empty (" & mainUserRecordID & "). Unable to compile short lilst of similar user records.")
Exit Sub
End If
'we can't start a new short list until the previous short list has been completely emptied of user records
shortListOfSimilarUserRecordIDs.Clear()
shortListOfSimilarUserRecordIDs.Add("")
'now load up the fields of the main user record into an array list
Dim mainUserRecordFieldsArrayList As New ArrayList
mainUserRecordFieldsArrayList = userRecordArrayHandler.ReturnGenericFieldsInArrayList(mainUserRecordID)
mainUserRecordFieldsArrayList.Sort()
'now go through all the user records which apply to the current user
'load all the user record fields into arraylists, one by one.
Dim arrayProcessor As New ArrayProcessingClass
Dim localUserRecordIDAL As New ArrayList
localUserRecordIDAL = clientInfoHolder(clientID).GetUserRecordIDArrayList
Dim URIDIndexMax As Integer = localUserRecordIDAL.Count - 1
For URIDIndex = 1 To URIDIndexMax 'do for each user record loaded in memory
Dim tempURID As String = localUserRecordIDAL(URIDIndex).ToString
Dim tempURGenericFieldArrayList As New ArrayList
tempURGenericFieldArrayList = userRecordArrayHandler.ReturnGenericFieldsInArrayList(tempURID)
tempURGenericFieldArrayList.Sort()
Dim textProcessing As New TextProcessingClass
If arrayProcessor.ArrayListStringEquals(mainUserRecordFieldsArrayList, tempURGenericFieldArrayList) Then
'do nothing 'ignore the identical user record
ElseIf (IsSimilarUserRecord(mainUserRecordFieldsArrayList, tempURGenericFieldArrayList)) Then 'check if user record array is similar to new user record
'if it is we add the user record id to the short list
shortListOfSimilarUserRecordIDs.Add(tempURID)
End If
Next URIDIndex
'if none found
If shortListOfSimilarUserRecordIDs.Count < 2 Then 'count = 0 or 1
shortListOfSimilarUserRecordIDs.Clear()
End If
End Sub
Public Function IsSimilarUserRecord(ByVal arraylist1 As ArrayList, ByVal arraylist2 As ArrayList, Optional ByVal allowableNumberOfElementsToBeNonIdentical As Integer = 1) As Boolean
'stuff
End Function
Now what is happening is that in the purple line I am calling IsSimilarUserRecord. All arguments are passed, Byval (not Byref). When I call IsSimilarUserRecord for the first time, mainUserRecordFieldsArrayList and tempURGenericFieldArrayList are passed into IsSimilarUserRecord without a problem. However, when IsSimilarUserRecord returns its boolean value, the 2 array lists: mainUserRecordFieldsArrayList and tempURGenericFieldArrayList are both emptied of their contents. This should not be happening, as their contents were passed ByVal, so should be unaltered after the boolean value is returned.
In itself this wouldn't be a problem but because the contents of mainUserRecordFieldsArrayList have to be repeatedly used (as it is contained in a For loop), after the 1st loop, that array list is useless.
Can somebody explain to me why the array lists are getting emptied, whenever I call IsSimilarUserRecord and pass the 2 array to it?
Thanks