Hey guys, so I am creating a List(Of String), always of size 9.
This list contains True/False values. I need to go through this list and find the 3 values that are True (will never be more than 3, but could be less) and then set 3 string values in my code to the 3 index's of those values + 1.
Here is my current code:
Private Sub SetDenialReasons(ByVal LoanData As DataRow)
        Dim reasons As New List(Of String)
        With reasons
            .Add(LoanData.Item("IsDenialReasonDTI").ToString)
            .Add(LoanData.Item("IsDenialReasonEmploymentHistory").ToString)
            .Add(LoanData.Item("IsDenialReasonCreditHistory").ToString)
            .Add(LoanData.Item("IsDenialReasonCollateral").ToString)
            .Add(LoanData.Item("IsDenialReasonCash").ToString)
            .Add(LoanData.Item("IsDenialReasonInverifiableInfo").ToString)
            .Add(LoanData.Item("IsDenialReasonIncomplete").ToString)
            .Add(LoanData.Item("IsDenialReasonMortgageInsuranceDenied").ToString)
            .Add(LoanData.Item("IsDenialReasonOther").ToString)
        End With
        Dim count As Integer = 0
        For Each item As String In reasons
            If item = "True" Then
                count += 1
            End If
        Next
        If count = 1 Then
            DenialReason1 = (reasons.IndexOf("True") + 1).ToString
        ElseIf count = 2 Then
            DenialReason1 = (reasons.IndexOf("True") + 1).ToString
            DenialReason2 = (reasons.LastIndexOf("True") + 1).ToString
        ElseIf count >= 3 Then
            Dim tempIndex As Integer = reasons.IndexOf("True")
            DenialReason1 = (reasons.IndexOf("True") + 1).ToString
            DenialReason2 = (reasons.IndexOf("True", tempIndex, reasons.Count - 1) + 1).ToString
            DenialReason3 = (reasons.LastIndexOf("True") + 1).ToString
        End If
    End Sub
I had 3 True's next to each other in the array and the code failed with an exception saying count must be positive or something.
Now if there are less than 3 True's, it should set the remaining DenialReason's that haven't been set yet as blank (however they are set as blank in the constructor already to account for this).
Any ideas?