Sub Process_Globals
Type ScoreSheet (CurrentRound As Int, SelectedJudge As Int, SelectedEntry As Int, SelectedCategory As Int, Score As Int)
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim ScoreSheets As List
ScoreSheets.Initialize
ScoreSheets.Add(CreateScoreSheet(0, 2, 0, 0, 4))
ScoreSheets.Add(CreateScoreSheet(0, 2, 0, 1, 3))
ScoreSheets.Add(CreateScoreSheet(0, 2, 0, 2, 3))
ScoreSheets.Add(CreateScoreSheet(0, 2, 0, 3, 4))
Log("Total scores for Round 1, Judge 3, Entry 1 = " & CalculateScoreByRoundJudgeEntry(ScoreSheets, 0, 2, 0))
ScoreSheets.Add(CreateScoreSheet(0, 2, 1, 0, 2))
ScoreSheets.Add(CreateScoreSheet(0, 2, 1, 1, 4))
ScoreSheets.Add(CreateScoreSheet(0, 2, 1, 2, 3))
ScoreSheets.Add(CreateScoreSheet(0, 2, 1, 3, 2))
Log("Total scores for Round 1, Judge 3, Entry 2 = " & CalculateScoreByRoundJudgeEntry(ScoreSheets, 0, 2, 1))
Log("Total scores for Round 1, Judge 3 = " & CalculateScoreByRoundJudge(ScoreSheets, 0, 2))
Log("Score for Round 1, Judge 3, Entry 1, Category 4 before setting new value = " & GetScoreByRoundJudgeEntryCategory(ScoreSheets, 0, 2, 0, 3))
' Update score for Round 1, Judge 3, Entry 1, Category 4 from 4 to 1
SetScoreByRoundJudgeEntryCategory(ScoreSheets, 0, 2, 0, 3, 1)
Log("Score for Round 1, Judge 3, Entry 1, Category 4 after setting new value = " & GetScoreByRoundJudgeEntryCategory(ScoreSheets, 0, 2, 0, 3))
Log("Total scores for Round 1, Judge 3 after setting new score = " & CalculateScoreByRoundJudge(ScoreSheets, 0, 2))
End Sub
Sub GetScoreByRoundJudgeEntryCategory (ScoreSheetList As List, CurrentRound As Int, SelectedJudge As Int, SelectedEntry As Int, SelectedCategory As Int) As Int
For Each item As ScoreSheet In ScoreSheetList
If item.CurrentRound = CurrentRound And _
item.SelectedJudge = SelectedJudge And _
item.SelectedEntry = SelectedEntry And _
item.SelectedCategory = SelectedCategory Then
Return item.Score
End If
Next
Return 0 ' not found
End Sub
Sub SetScoreByRoundJudgeEntryCategory (ScoreSheetList As List, CurrentRound As Int, SelectedJudge As Int, SelectedEntry As Int, SelectedCategory As Int, Score As Int)
For Each item As ScoreSheet In ScoreSheetList
If item.CurrentRound = CurrentRound And _
item.SelectedJudge = SelectedJudge And _
item.SelectedEntry = SelectedEntry And _
item.SelectedCategory = SelectedCategory Then
item.Score = Score
End If
Next
End Sub
Sub CalculateScoreByRoundJudgeEntry (ScoreSheetList As List, CurrentRound As Int, SelectedJudge As Int, SelectedEntry As Int) As Int
Dim TotalScore As Int
For Each item As ScoreSheet In ScoreSheetList
If item.CurrentRound = CurrentRound And _
item.SelectedJudge = SelectedJudge And _
item.SelectedEntry = SelectedEntry Then
TotalScore = TotalScore + item.Score
End If
Next
Return TotalScore
End Sub
Sub CalculateScoreByRoundJudge (ScoreSheetList As List, CurrentRound As Int, SelectedJudge As Int) As Int
Dim TotalScore As Int
For Each item As ScoreSheet In ScoreSheetList
If item.CurrentRound = CurrentRound And _
item.SelectedJudge = SelectedJudge Then
TotalScore = TotalScore + item.Score
End If
Next
Return TotalScore
End Sub
Public Sub CreateScoreSheet (CurrentRound As Int, SelectedJudge As Int, SelectedEntry As Int, SelectedCategory As Int, Score As Int) As ScoreSheet
Dim t1 As ScoreSheet
t1.Initialize
t1.CurrentRound = CurrentRound
t1.SelectedJudge = SelectedJudge
t1.SelectedEntry = SelectedEntry
t1.SelectedCategory = SelectedCategory
t1.Score = Score
Return t1
End Sub