Wo die Werte angezeigt werden, ist nebensächlich.
Nimm Dir mal die Datei test.txt vor nachdem Du Die abgespeichert hast.
Ich hab Deinen Code mal etwas um Listenfunktionalitäten erweitert.
Speichern in Datei, nur als Ziel halt die Listen.
Für ne bessere Übersicht hab ich die Listen strukturiert.
Foreach .. Next
Code: Alles auswählen
Structure wertung
h.l
g.l
EndStructure
Global NewList ergebnisse.wertung()
Global NewList HB.wertung()
Global NewList MB.wertung()
Procedure savelists()
ClearList(ergebnisse())
For n=11 To 19
AddElement(ergebnisse())
ergebnisse()\h=Val(StringField(GetGadgetText(n),1,":"))
ergebnisse()\g=Val(StringField(GetGadgetText(n),2,":"))
Next
ClearList(HB())
For n=21 To 29
AddElement(HB())
HB()\h=Val(StringField(GetGadgetText(n),1,":"))
HB()\g=Val(StringField(GetGadgetText(n),2,":"))
Next
ClearList(MB())
For n=31 To 39
AddElement(MB())
MB()\h=Val(StringField(GetGadgetText(n),1,":"))
MB()\g=Val(StringField(GetGadgetText(n),2,":"))
Next
EndProcedure
Procedure showlists()
Debug "*************"
ForEach ergebnisse()
Debug Str(ergebnisse()\H)+":"+Str(ergebnisse()\g)
Next
ForEach HB()
Debug Str(HB()\H)+":"+Str(HB()\g)
Next
ForEach MB()
Debug Str(MB()\H)+":"+Str(MB()\g)
Next
EndProcedure
Procedure shshowlists()
SortStructuredList(ergebnisse(),0,OffsetOf(wertung\h),#PB_Sort_Long)
Debug "****ergebnisse sortiert nach wertung\h aufsteigend ****"
ForEach ergebnisse()
Debug Str(ergebnisse()\h)+":"+Str(ergebnisse()\g)
Next
EndProcedure
Procedure sgshowlists()
SortStructuredList(ergebnisse(),0,OffsetOf(wertung\g),#PB_Sort_Long)
Debug "****ergebnisse sortiert nach wertung\g aufsteigend ****"
ForEach ergebnisse()
Debug Str(ergebnisse()\h)+":"+Str(ergebnisse()\g)
Next
EndProcedure
If OpenWindow(0,100,100,800,210,"Fussball-Tipp",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
PanelGadget (600, 5, 25, 790, 180)
AddGadgetItem(600,-1,"Spieltag")
If CreateToolBar(0, WindowID(0))
ToolBarStandardButton(500, #PB_ToolBarIcon_New)
ToolBarStandardButton(501, #PB_ToolBarIcon_Open)
ToolBarStandardButton(502, #PB_ToolBarIcon_Save)
ToolBarStandardButton(503, #PB_ToolBarIcon_Print)
EndIf
Macro Spiele(ID, xKoordinate, yKoordinate, Text)
StringGadget(ID,xKoordinate,yKoordinate,50,16, Text,#PB_String_BorderLess|#PB_Text_Center|#PB_String_ReadOnly)
SetGadgetColor(ID,#PB_Gadget_BackColor,$000000)
SetGadgetColor(ID,#PB_Gadget_FrontColor,$0000FF)
EndMacro
Macro Getippte_Ergebnisse(ID, xKoordinate, yKoordinate, Text)
StringGadget(ID,xKoordinate,yKoordinate,50,20, Text,#PB_Text_Center|#PB_String_Numeric)
SetGadgetColor(ID,#PB_Gadget_BackColor,BackColor)
SetGadgetColor(ID,#PB_Gadget_FrontColor,FrontColor)
EndMacro
Macro Spielernamen(ID, yKoordinate, Text)
StringGadget(ID,600,yKoordinate,140,18, Text,#PB_String_BorderLess|#PB_Text_Center|#PB_String_ReadOnly)
SetGadgetColor(ID,#PB_Gadget_BackColor,$00FFFF)
SetGadgetColor(ID,#PB_Gadget_FrontColor,$000000)
EndMacro
For n = 1 To 9
Spiele (n, 60*n, 30,Str(n))
Next
BackColor = $0000FF
FrontColor = $33FFFF
For n = 11 To 19
Getippte_Ergebnisse (n, 60*(n-10), 60, ":")
Next
BackColor = $00FFFF
FrontColor = $000000
For n = 21 To 29
Getippte_Ergebnisse (n, 60*(n-20), 100, ":")
Next
For n = 31 To 39
Getippte_Ergebnisse (n, 60*(n-30), 125, ":")
Next
Spielernamen (300, 100, "Harald Baumann")
Spielernamen (301, 125, "Markus Bräutigam")
ButtonGadget(325,600,30,140,50,"Vergleichen")
;Leeres Gadget
StringGadget(1000,1800,20,50,20,":")
;------------------------------------------
;-Punkte
StringGadget (20,750,100,30,20,Str(Punkte),#PB_String_BorderLess|#PB_Text_Center|#PB_String_ReadOnly)
StringGadget (30,750,125,30,20,Str(Punkte),#PB_String_BorderLess|#PB_Text_Center|#PB_String_ReadOnly)
For n = 20 To 30 Step 10
SetGadgetColor(n,#PB_Gadget_BackColor,$FFFFFF)
SetGadgetColor(n,#PB_Gadget_FrontColor,$000000)
Next
;-Panel1
AddGadgetItem(600,-1,"Tagessieger")
;-Panel2
AddGadgetItem(600,-1,"Gesamtwertung")
;----------------------------------------------
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
;-Neu
If Event = #PB_Event_Menu
If EventMenu()=500
For n = 11 To 19
SetGadgetText(n,":")
Next
For n = 21 To 29
SetGadgetText(n,":")
Next
For n = 31 To 39
SetGadgetText(n,":")
Next
EndIf
savelists()
showlists()
shshowlists()
sgshowlists()
;-Öffnen
If EventMenu()=501
StandardDatei$ = "D:\Programme\PureBasic\test.txt"
Pattern$ = "Text-Dateien (*.txt)|*.txt|Alle Dateien (*.*)|*.*"
PatternPosition = 1
DateiName$ = OpenFileRequester("Öffnen ...", StandardDatei$, Pattern$, PatternPosition)
If ReadFile(0,DateiName$)
n=11
While Not Eof(0) And n<=19
Text$ = ReadString(0)
SetGadgetText(n,Text$)
n+1
Wend
n=21
While Not Eof(0) And n<=29
Text$ = ReadString(0)
SetGadgetText(n,Text$)
n+1
Wend
n=31
While Not Eof(0) And n<=39
Text$ = ReadString(0)
SetGadgetText(n,Text$)
n+1
Wend
EndIf
EndIf
savelists()
showlists()
shshowlists()
sgshowlists()
;-Speichern
If EventMenu()=502
StandardDatei$ = "D:\Programme\PureBasic\test.txt"
Pattern$ = "Text-Dateien (*.txt)|*.txt|Alle Dateien (*.*)|*.*"
PatternPosition = 1
DateiName$ = SaveFileRequester("Speichern unter...", StandardDatei$, Pattern$, PatternPosition)
CreateFile (0,DateiName$)
For n=11 To 19
WriteStringN(0,GetGadgetText(n))
Next
For n=21 To 29
WriteStringN(0,GetGadgetText(n))
Next
For n=31 To 39
WriteStringN(0,GetGadgetText(n))
Next
CloseFile(0)
savelists()
showlists()
shshowlists()
sgshowlists()
EndIf
EndIf
;-Vergleich
If Event = #PB_Event_Gadget And EventGadget() = 325
;Wenn Ergebiss noch nicht eingegeben sind sollen keine Punkte für dieses Spiel ausgeben werden
Leer$ = GetGadgetText(1000)
;-1.Spieler
;1_Spiel:
Erg$ = GetGadgetText(11)
Tipp$ = GetGadgetText(21)
Gosub Berechnung
P1 = Punkte
;2_Spiel:
Erg$ = GetGadgetText (12)
Tipp$ = GetGadgetText (22)
Gosub Berechnung
P2 = Punkte
;3_Spiel:
Erg$ = GetGadgetText (13)
Tipp$ = GetGadgetText (23)
Gosub Berechnung
P3 = Punkte
;4_Spiel:
Erg$ = GetGadgetText(14)
Tipp$ = GetGadgetText(24)
Gosub Berechnung
P4 = Punkte
;5_Spiel:
Erg$ = GetGadgetText(15)
Tipp$ = GetGadgetText(25)
Gosub Berechnung
P5 = Punkte
;6_Spiel:
Erg$ = GetGadgetText(16)
Tipp$ = GetGadgetText(26)
Gosub Berechnung
P6 = Punkte
;7_Spiel:
Erg$ = GetGadgetText(17)
Tipp$ = GetGadgetText(27)
Gosub Berechnung
P7 = Punkte
;8_Spiel:
Erg$ = GetGadgetText(18)
Tipp$ = GetGadgetText(28)
Gosub Berechnung
P8 = Punkte
;9_Spiel:
Erg$ = GetGadgetText(19)
Tipp$ = GetGadgetText(29)
Gosub Berechnung
P9 = Punkte
Gosub Punkte
SetGadgetText(20,Str(Punkte))
Punkte = 0
;-2.Spieler
;1_Spiel:
Erg$ = GetGadgetText(11)
Tipp$ = GetGadgetText(31)
Gosub Berechnung
P1 = Punkte
;2_Spiel:
Erg$ = GetGadgetText (12)
Tipp$ = GetGadgetText (32)
Gosub Berechnung
P2 = Punkte
;3_Spiel:
Erg$ = GetGadgetText (13)
Tipp$ = GetGadgetText (33)
Gosub Berechnung
P3 = Punkte
;4_Spiel:
Erg$ = GetGadgetText(14)
Tipp$ = GetGadgetText(34)
Gosub Berechnung
P4 = Punkte
;5_Spiel:
Erg$ = GetGadgetText(15)
Tipp$ = GetGadgetText(35)
Gosub Berechnung
P5 = Punkte
;6_Spiel:
Erg$ = GetGadgetText(16)
Tipp$ = GetGadgetText(36)
Gosub Berechnung
P6 = Punkte
;7_Spiel:
Erg$ = GetGadgetText(17)
Tipp$ = GetGadgetText(37)
Gosub Berechnung
P7 = Punkte
;8_Spiel:
Erg$ = GetGadgetText(18)
Tipp$ = GetGadgetText(38)
Gosub Berechnung
P8 = Punkte
;9_Spiel:
Erg$ = GetGadgetText(19)
Tipp$ = GetGadgetText(39)
Gosub Berechnung
P9 = Punkte
Gosub Punkte
SetGadgetText(30,Str(Punkte))
Punkte = 0
;-Programm-Ende
EndIf
Until Quit = 1
End
Berechnung:
If Left(Erg$,3) = Left (Leer$,3)
Punkte = 0
Gosub Leer
EndIf
If Mid(Erg$,1,1) = Mid(Tipp$,1,1) And Mid(Erg$,3,1) = Mid(Tipp$,3,1)
Punkte = 7
Else
Punkte = 0
EndIf
Goto Sprung
Leer:
FakeReturn
Sprung:
If Punkte < 7 And Mid(Erg$,1,1) = Mid(Erg$,3,1) And Mid(Tipp$,1,1) = Mid(Tipp$,3,1)
Punkte = 5
Else
Punkte = Punkte
EndIf
If Left(Erg$,3) = Left (Leer$,3)
Punkte = Punkte
Gosub Leer1
EndIf
If Punkte < 7 And Mid(Erg$,1,1) > Mid(Erg$,3,1) And Mid(Tipp$,1,1) > Mid(Tipp$,3,1)
Punkte = 3
Else
Punkte = Punkte
EndIf
Goto Sprung1
Leer1:
FakeReturn
Sprung1:
If Punkte < 7 And Mid(Erg$,1,1) < Mid(Erg$,3,1) And Mid(Tipp$,1,1) < Mid(Tipp$,3,1)
Punkte = 3
Else
Punkte = Punkte
EndIf
If Left(Erg$,3) = Left (Leer$,3)
Punkte = 0
Gosub Leer2
EndIf
If Punkte < 7 And Mid(Erg$,1,1) = Mid(Tipp$,1,1)
Punkte = Punkte + 1
ElseIf Punkte < 7 And Mid(Erg$,3,1) = Mid(Tipp$,3,1)
Punkte = Punkte + 1
EndIf
Goto Sprung2
Leer2:
FakeReturn
Sprung2:
Return
Punkte:
Punkte = P1+P2+P3+P4+P5+P6+P7+P8+P9
If P1 = 7
ExtraP = ExtraP +1
EndIf
If P2 = 7
ExtraP = ExtraP +1
EndIf
If P3 = 7
ExtraP = ExtraP +1
EndIf
If P4 = 7
ExtraP = ExtraP +1
EndIf
If P5 = 7
ExtraP = ExtraP +1
EndIf
If P6 = 7
ExtraP = ExtraP +1
EndIf
If P7 = 7
ExtraP = ExtraP +1
EndIf
If P8 = 7
ExtraP = ExtraP +1
EndIf
If P9 = 7
ExtraP = ExtraP +1
EndIf
If ExtraP >= 3
Punkte = Punkte +2
EndIf
ExtraP = 0
If P1 >= 3
ExtraP = ExtraP + 1
EndIf
If P2 >= 3
ExtraP = ExtraP + 1
EndIf
If P3 >= 3
ExtraP = ExtraP + 1
EndIf
If P4 >= 3
ExtraP = ExtraP + 1
EndIf
If P5 >= 3
ExtraP = ExtraP + 1
EndIf
If P6 >= 3
ExtraP = ExtraP + 1
EndIf
If P7 >= 3
ExtraP = ExtraP + 1
EndIf
If P8 >= 3
ExtraP = ExtraP + 1
EndIf
If P9 >= 3
ExtraP = ExtraP + 1
EndIf
If ExtraP >= 6
Punkte = Punkte + 2
EndIf
ExtraP = 0
P1 = 0
P2 = 0
P3 = 0
P4 = 0
P5 = 0
P6 = 0
P7 = 0
P8 = 0
P9 = 0
Return