Hi,
I am trying to do some calculations which require some kind of depth 1st search algorithm. I have some ideas as to how to do it, but I think there should be a better way to do it. Hopefully someone can give me some advice. Thanks in advance. FYI, I'm not an expert in coding, would appreciate if replies are simple. Thanks again.
I have a table, tblEvent, with the following columns: EventID, PreEventID, EventType, EventValue, Score
The EventID (1) is related to PreEventID (many) hence forming a tree structure.
What I need to do is to determine TotScore for certain type of events under a specified TopEvent, which can be any event in the table. Note that TotScore = (Sum of score of events with EventType = "CSQ")
Another point to note is that EventType "CSQ" is always at the bottom of the tree, i.e. no other events' PreEventID points to an event with EventType = "CSQ". Furthermore gor each branch in the tree structure there are either 3 OR 4 levels.
Here's a (far from perfect) pseudo code that I came up with:
I can see that there are a lot of repetitions, but I am not sure how that can be make full use of.
I am trying to do some calculations which require some kind of depth 1st search algorithm. I have some ideas as to how to do it, but I think there should be a better way to do it. Hopefully someone can give me some advice. Thanks in advance. FYI, I'm not an expert in coding, would appreciate if replies are simple. Thanks again.
I have a table, tblEvent, with the following columns: EventID, PreEventID, EventType, EventValue, Score
The EventID (1) is related to PreEventID (many) hence forming a tree structure.
What I need to do is to determine TotScore for certain type of events under a specified TopEvent, which can be any event in the table. Note that TotScore = (Sum of score of events with EventType = "CSQ")
Another point to note is that EventType "CSQ" is always at the bottom of the tree, i.e. no other events' PreEventID points to an event with EventType = "CSQ". Furthermore gor each branch in the tree structure there are either 3 OR 4 levels.
Here's a (far from perfect) pseudo code that I came up with:
Code:
rst1 = (select events with preevent = TopEvent's EventID)
If Not rst1.eof AND rst1.BOF then 'If there are child events
Do until rst1.eof
If EventType = "CSQ" then TotScore = TotScore + Score
rst2 = (select events with preevent = rst1!EventID)
If Not rst2.eof AND rst2.BOF then
Do Until rst2.EOF
If EventType = "CSQ" then TotScore = TotScore + Score
rst3 = (select events with preevent = rst2!EventID)
If Not rst3.eof AND rst3.BOF then
Do Until rst3.EOF
If EventType = "CSQ" then TotScore = TotScore + Score
rst4 = (select events with preevent = rst3!EventID)
If Not rst4.eof AND rst4.BOF then
Do Until rst4.EOF
If EventType = "CSQ" then TotScore = TotScore + Score
Loop
End if
rst4.close
loop
end if
rst3.close
Loop
End If
rst2.Close
Loop
End if
rst1.Close
I can see that there are a lot of repetitions, but I am not sure how that can be make full use of.