I am having trouble getting a correct response when searching through each of my datarows. While stepping through during debugging, I am seeing the boolean response is getting triggered even if one row does not match my selected string. I just want to search all of the rows and if at least one row matches(a single textbox in that row), everything will be fine and the error in dgv will not be populated. Am I missing something simple here?

Party as Boolean = False
For each eventrow as Datarow in PFC_Xpress.Tables("Event Info").rows
    If Incident_Type.text = "Party" Then
For Each personrow as datarow in PFC_Xpress.Tables("Person").rows
    If Event_Assoc1.text <> "Guest" then
    Party = True
End If
Next
End If
Next

I may be very wrong, but it seems to me that you are testing an awful lot of times (the number of persons x the number of events) whether Incident_Type.text = "Party" and "Event_Assoc1.text <> "Guest"

Unless I'm missing something major, or you are not telling us something this :

dim Party as boolean = (Incident_Type.text = "Party") andalso (Event_Assoc1.text <> "Guest")

would achieve the same as the code you show us.

Which begs the question, are you assuming that Incident_Type and Event_Assoc1 are getting updated just by foreaching those tables?

Edited 2 Years Ago by PerplexedB

P, not sure if I am getting your question completely. Sorry for the confusion. When the form is completed, there is only one row in my data table containing 'Incident_Type', but if there is more than one person, the user adds another row to the data table (so for kicks, let's say 3 people were added, thus 3 rows). Afterwards, the user saves the form and then uses a button (called Validation), where I am searching through the rows to make sure the form is correct.

In this case, if the Incident_Type = Party, but none of the rows where Event_Assoc1 is, contains "Guest" then a message is generated. My problem is what I have so far generates the message even if Guest is present, but the other 2 rows are different.

Gus, maybe it would help if you could give us the structure of the tables "Event_Info" and "Person".

At this stage, I don't see the relationship between your traversing the tables and the testing of the values of what seems to be textboxes (Incident_Type and Event_Assoc1)

You are using 2 Tables, reading the row of the first table, then reading all the rows of second table, but you are not using any value from any row in any table

In your IF CONDITION you have (IF TEXTBOX.TEXT = STRING), the table rows loop is useless if you not reading the value from tables..

So, what you are trying to do exactly?

That's what I thought too, but the problem I am having is the boolean method is getting triggered because it is searching through each of the rows.

What I am hoping to accomplish is: If the first row doesn't meet the condition, but the second row does, the equation is correct (or any row for that matter). Running a test right now, I have the 2nd row returning with "guest" but the first row does not.

That's what I thought too, but the problem I am having is the boolean method is getting triggered because it is searching through each of the rows.

You mean that the code you present us here returns true in party? But that is because it depends exclusively on the value in Incident_Type.text = "Party" and Event_Assoc1.text <> "Guest" It is not affected by what's in the tables.

Well, here's what I ultimately want to achieve.

1) Eventrow will only have one datarow. If Incident_Type = Party then

2) Search each row in PersonRow under "Event Association"

3) If any of those rows contain "Guest" then Party equals False

Right now, if even one row does not contain "Guest" Party is changed to True.

I hope this helps. I'm not only beat, but stumped and frustrated.

Gus :), relax.

  dim Party as Boolean = False
    if PFC_Xpress.Tables("Event Info").rows(0)("Incident_Type") = "Party" then
        dim hasGuest as boolean = false
        For Each personrow as datarow in PFC_Xpress.Tables("Person").rows
            If personrow("Event_Assoc1") = "Guest" then
                hasGuest = true
                exit for
            endif
        Next
        Party =iif(hasGuest,false,true)
    endif

I'm assuming a) that the unique EventRow will be in the first row of the datatable and b) that if the Incident_Type is not party, well that Party should be false.

Edited 2 Years Ago by PerplexedB

Comments
great response!

Thanks Perplexed. Never knew about 'iif' for multiple boolean so always learning something new. it's been rough between the long hours at work and always active at home. thanks again for the help!

This question has already been answered. Start a new discussion instead.