02-21-2023, 05:59 PM
Two examples for a dynamic and a static two-dimensional field.
A static field is reinitialized with 0 after erase and can then be filled with new values again. However, it cannot be redimensioned like a dynamic field. So, 10 * 10 cannot become an 8 * 8 field.
Dynamic array with Redim:
Static array with Erase:
A static field is reinitialized with 0 after erase and can then be filled with new values again. However, it cannot be redimensioned like a dynamic field. So, 10 * 10 cannot become an 8 * 8 field.
Dynamic array with Redim:
Code: (Select All)
'Zweidimensionales Feld mit Redim neu dimensionieren - 29. Dez. 2022
$Console:Only
Option _Explicit
Option Base 1
Dim As Integer neuDimensionZeile, neuDimensionSpalte
Dim As Integer zeilenDim, spaltenDim
Dim As Integer a, b, i, j, y, z
Locate 2, 2
Input "Feldimension Zeilen : ", zeilenDim
Locate 3, 2
Input "Felddimension Spalten: ", spaltenDim
Dim As Integer zweiDimfeld(zeilenDim, spaltenDim)
Locate CsrLin + 2, 2
z = 1
For i = 1 To zeilenDim
For j = 1 To spaltenDim
zweiDimfeld(i, j) = z
Print Using "## "; zweiDimfeld(i, j),
z = z + 1
Next
Print: Locate , 2
Next
'Vor Neudimensionierung Speicher freigeben. Ist bei Anwendung
'von REDIM nicht noetig, da dieser ERASE + DIM zusammenfasst - S.188
'Erase zweiDimfeld
'Feld neu dimensionieren
Locate CsrLin + 2, 2
Input "Neue Feldimension Zeile : ", neuDimensionZeile
Locate CsrLin + 0, 2
Input "Neue Feldimension Spalte: ", neuDimensionSpalte
ReDim zweiDimfeld(neuDimensionZeile, neuDimensionSpalte)
Locate CsrLin + 2, 2
y = 1
For a = 1 To neuDimensionZeile
For b = 1 To neuDimensionSpalte
zweiDimfeld(a, b) = y
Print Using "## "; zweiDimfeld(a, b),
y = y + 1
Next
Print: Locate , 2
Next
Locate CsrLin + 3, 2
End
Static array with Erase:
Code: (Select All)
'Statisches Array. Keine Redimensionierung moeglich - 21. Feb. 2023
$Console:Only
Option _Explicit
Option Base 1
Const Elemente = 10
Dim As Integer Feld(Elemente, Elemente)
Dim As Integer i, j, z
Locate CsrLin + 2, 2
z = 1
For i = 1 To 10
For j = 1 To 10
Feld(i, j) = z
Print Using "### "; Feld(i, j),
z = z + 1
Next
Print: Locate , 2
Next
Locate CsrLin + 2, 2
Print "Die Werte im Feld existieren noch."
'Das Array existiert noch!
Locate CsrLin + 2, 2
z = 1
For i = 1 To 10
For j = 1 To 10
Print Using "### "; Feld(i, j),
z = z + 1
Next
Print: Locate , 2
Next
'Statische Arrays werden nach ERASE neu initialisiert -> 0, S.188
Erase Feld
Locate CsrLin + 2, 2
Print "Das Feld wurde mit ERASE neu initialisiert -> 0."
'Jetzt ist das statische Array neu initialisiert mit 0,
'da keine neuen Werte eingegeben wurden.
Locate CsrLin + 2, 2
z = 1
For i = 1 To 10
For j = 1 To 10
Print Using "### "; Feld(i, j),
z = z + 1
Next
Print: Locate , 2
Next
'Only for: Press any key
Locate CsrLin + 3, 2
End