Something is wrong with my logic, I really need help. I've got an excel file with 6 columns. On column 5 it contains various phrases. I'm looking for either ('RightScan' or 'LeftScan'). Both of these will have the same unique CaseID. Each case will have right and left sided info. It loops from the end of the file to the top as the most recent records are at the bottom of the excel file. So, I check for a phrase, if its found then get its unique number. I then check my existing CaseID numbers for this new one. If it already exists then don't do anything else as I've started from the end so i have the most recent. If it doesn't exist then add. Here are my variables:


VB Code:
  1. Public Structure CaseDetails
  2.         Dim rghtTime As String
  3.         Dim rghtDate As String
  4.         Dim lftTime As String
  5.         Dim lftDate As String
  6.         Dim CaseID As String
  7.         Dim UserID As String
  8.         Dim RClass As String
  9.         Dim LClass As String
  10.         Dim RCode As String
  11.         Dim LCode As String
  12.         Dim LFound As Boolean
  13.         Dim RFound As Boolean
  14.     End Structure
  15.  
  16.     Dim CaseCount As Integer = 0
  17.     Dim myCases(9000) As CaseDetails


Here is the code for the Rightside. The problem has something to do with the q loop but I don't know what. I keep just getting caseCount = 1. It doesn't seem to want to add any new cases:

VB Code:
  1. For r = oSht.UsedRange.Rows.Count To 1 Step -1
  2.             Console.WriteLine("Passed the Null Check of the Do Loop")
  3.  
  4.   If CType(oSht.Cells(r, 5), Range).Value.ToString = "RightScan" Then
  5.                 ClassificationType = "Right"
  6.                 Console.WriteLine("Right Classification in Text Cell")
  7.  
  8. '.
  9. '.
  10. '.
  11.  Select Case ClassificationType
  12.  
  13.                 Case "Right"
  14.                     'CHECK FOR DATA IN EXISTING CASES
  15.                     If CaseCount = 0 Then    'IF 1st EVER CASE THEN
  16.                         'Just add data
  17.                         myCases(CaseCount).RClass = CType(oSht.Cells(r, 6), Range).Value.ToString
  18.                         myCases(CaseCount).rghtDate = CType(oSht.Cells(r, 2), Range).Value.ToString.Substring(1, 10)
  19.                         myCases(CaseCount).rghtTime = CType(oSht.Cells(r, 2), Range).Value.ToString.Substring(11, 5)
  20.                         myCases(CaseCount).RCode = ClassifyCode(CType(oSht.Cells(r, 6), Range).Value.ToString)
  21.                         myCases(CaseCount).CaseID = CType(oSht.Cells(r, 3), Range).Value.ToString
  22.                         myCases(CaseCount).UserID = CType(oSht.Cells(r, 1), Range).Value.ToString
  23.                         myCases(CaseCount).RFound = True
  24.                         CaseCount += 1 'Update at the end
  25.                         Console.WriteLine(CaseCount)
  26.                         Console.WriteLine("Added to case count")
  27.                     Else
  28.  
  29.                         For q = 0 To CaseCount Step 1    'CHECK FOR CASE_ID AGAINST EXISTING CASE_ID's IN ARRAY - IS THIS WRONG??
  30.                             If myCases(q).CaseID = CType(oSht.Cells(r, 3), Range).Value.ToString Then
  31.                                 Console.WriteLine("Found match")  'CASE_ID has been Found - BUT Does it have RightSided Data?
  32.                                 If myCases(q).RFound = True Then  'Right Sided Data Exists
  33.                                     Console.WriteLine("Data on right side exists")
  34.                                     Exit For
  35.                                 Else   'CASE_ID ALREADY EXISTS BUT NO RIGHT SIDED DATA IS PRESENT SO ADD IT
  36.                                     myCases(q).RClass = CType(oSht.Cells(r, 6), Range).Value.ToString
  37.                                     myCases(q).rghtDate = CType(oSht.Cells(r, 2), Range).Value.ToString.Substring(1, 10)
  38.                                     myCases(q).rghtTime = CType(oSht.Cells(r, 2), Range).Value.ToString.Substring(11, 5)
  39.                                     myCases(q).RCode = ClassifyCode(CType(oSht.Cells(r, 6), Range).Value.ToString)
  40.                                     myCases(q).CaseID = CType(oSht.Cells(r, 3), Range).Value.ToString
  41.                                     myCases(q).UserID = CType(oSht.Cells(r, 1), Range).Value.ToString
  42.                                     myCases(q).RFound = True   'Data entered as Boolean
  43.                                     Exit For
  44.                                 End If
  45.                             End If
  46.                         Next
  47.                     End If
  48.  
  49.                     If q = CaseCount Then 'GOT ALL THE WAY THROUGH WITHOUT FINDING IT - SO ADD NEW CASE
  50.                         Console.WriteLine("Added a right classification")
  51.                         'Add the records to CURRENT CASECOUNT
  52.                         myCases(CaseCount).RClass = CType(oSht.Cells(r, 6), Range).Value.ToString
  53.                         myCases(CaseCount).rghtDate = CType(oSht.Cells(r, 2), Range).Value.ToString.Substring(1, 10)
  54.                         myCases(CaseCount).rghtTime = CType(oSht.Cells(r, 2), Range).Value.ToString.Substring(11, 5)
  55.                         myCases(CaseCount).RCode = ClassifyCode(CType(oSht.Cells(r, 6), Range).Value.ToString)
  56.                         myCases(CaseCount).CaseID = CType(oSht.Cells(r, 3), Range).Value.ToString
  57.                         myCases(CaseCount).UserID = CType(oSht.Cells(r, 1), Range).Value.ToString
  58.                         myCases(CaseCount).RFound = True
  59.                         CaseCount += 1 'THEN UPDATE AT THE END
  60.                         Console.WriteLine(CaseCount)
  61.                     End If
  62.  
  63. '.
  64. '.
  65. '.
  66. 'etc... Left and so on
  67. End Select
  68.  
  69. Next

It's not crashing. It's a problem with the loop but I still can't understand why. Can anyone offer a suggestion of any sort. I've been at this now for days.

Thanks