Code: Alles auswählen
CompilerIf #False
;{ reine arrays
; geht nicht mit Stringarrays
; Dimensionen
d1 = 10
d2 = 50
; array belegen
Dim test(d1, d2)
For x = 0 To d1
For y = 0 To d2
test(x, y) = x * d2 + y
Next
Next
; array anzeigen
For x = 0 To d1
For y = 0 To d2
Debug "(" + Str(x) + " / " + Str(y) + "): " + Str(test(x, y))
Next
Next
; array abspeichern
ptr = @test()
size.l = (d1+1) * (d2+1) * 4 ; long = 4 byte
Debug "size: " +Str(size)
If CreateFile(1, "C:\temp\arraytest.arr")
WriteData(ptr, size)
CloseFile(1)
EndIf
; neues Array kreieren
Dim testneu(d1, d2)
ptr = @testneu()
size.l = (d1+1) * (d2+1) * 4
; Array laden
If ReadFile(1, "C:\temp\arraytest.arr")
ReadData(ptr, size)
CloseFile(1)
EndIf
Debug""
Debug""
; neues array anzeigen
For x = 0 To d1
For y = 0 To d2
Debug "(" + Str(x) + " / " + Str(y) + "): " + Str(testneu(x, y))
Next
Next
;}
CompilerEndIf
CompilerIf #False
;{ Arrays mit Strukturen
; geht nicht mir Strukturen, die Strings beinhalten
Structure tst
a.l
b.l
c.l
d.b
e.w
f.f
EndStructure
d1 = 10
d2 = 50
; struktur belegen
Dim test.tst(d1, d2)
For x = 0 To d1
For y = 0 To d2
test(x, y)\a = x
test(x, y)\b = y
test(x, y)\c = x * d2 + y
test(x, y)\d = y
test(x, y)\e = x + y
test(x, y)\f = x * d2 / y
Next
Next
; struktur anzeigen
; For x = 0 To d1
; For y = 0 To d2
; Debug ""
; Debug "(" + Str(x) + " / " + Str(y) + ")"
; Debug "a: " + Str(test(x, y)\a)
; Debug "b: " + Str(test(x, y)\b)
; Debug "c: " + Str(test(x, y)\c)
; Debug "d: " + Str(test(x, y)\d)
; Debug "e: " + Str(test(x, y)\e)
; Debug "f: " + Strf(test(x, y)\f)
; Next
; Next
; Struktur abspeichern
ptr = @test()
size.l = (d1+1) * (d2+1) * SizeOf(tst)
Debug "size: " +Str(size)
If CreateFile(1, "C:\temp\arraytest.arr")
WriteData(ptr, size)
CloseFile(1)
EndIf
; neues array
Dim testneu.tst(d1, d2)
; Struktur laden
ptr = @testneu()
size.l = (d1+1) * (d2+1) * SizeOf(tst)
Debug "size: " +Str(size)
If ReadFile(1, "C:\temp\arraytest.arr")
ReadData(ptr, size)
CloseFile(1)
EndIf
; struktur anzeigen
For x = 0 To d1
For y = 0 To d2
Debug ""
Debug "(" + Str(x) + " / " + Str(y) + ")"
Debug "a: " + Str(testneu(x, y)\a)
Debug "b: " + Str(testneu(x, y)\b)
Debug "c: " + Str(testneu(x, y)\c)
Debug "d: " + Str(testneu(x, y)\d)
Debug "e: " + Str(testneu(x, y)\e)
Debug "f: " + StrF(testneu(x, y)\f)
Next
Next
;}
CompilerEndIf
CompilerIf #True
;{ Listen
;geht auch wieder nicht mit strings...
Structure tst
a.l
b.l
c.l
d.b
e.w
f.f
EndStructure
d1 = 10
d2 = 50
; struktur belegen
NewList test.tst()
For x = 0 To d1
For y = 0 To d2
AddElement(test())
test()\a = x
test()\b = y
test()\c = x * d2 + y
test()\d = y
test()\e = x + y
test()\f = x * d2 / y
Next
Next
;struktur anzeigen
; ResetList(test())
; While NextElement(test())
; Debug ""
; Debug "(" + Str(ListIndex(test())) + ")"
; Debug "a: " + Str(test()\a)
; Debug "b: " + Str(test()\b)
; Debug "c: " + Str(test()\c)
; Debug "d: " + Str(test()\d)
; Debug "e: " + Str(test()\e)
; Debug "f: " + StrF(test()\f)
; Wend
; Struktur abspeichern
; den pointer zum ersten Element erwischen)
SelectElement(test(), 0)
ptr = @test()
size.l = CountList(test()) * SizeOf(tst)
Debug "size: " +Str(size)
If CreateFile(1, "C:\temp\arraytest.arr")
WriteData(ptr, size)
CloseFile(1)
EndIf
; neue liste
NewList testneu.tst()
; elemente anhängen
For x = 0 To d1
For y = 0 To d2
AddElement(testneu())
Next
Next
; Struktur laden
; den pointer zum ersten Element erwischen)
SelectElement(testneu(), 0)
ptr = @testneu()
Debug ptr
;size.l = (d1+1) * (d2+1) * SizeOf(tst)
Debug "size: " +Str(size)
If ReadFile(1, "C:\temp\arraytest.arr")
ReadData(ptr, size)
CloseFile(1)
EndIf
;struktur anzeigen
ResetList(testneu())
While NextElement(testneu())
Debug ""
Debug "(" + Str(ListIndex(test())) + ")"
Debug "a: " + Str(testneu()\a)
Debug "b: " + Str(testneu()\b)
Debug "c: " + Str(testneu()\c)
Debug "d: " + Str(testneu()\d)
Debug "e: " + Str(testneu()\e)
Debug "f: " + StrF(testneu()\f)
Wend
;}
CompilerEndIf