02-27-2023, 07:05 PM
(This post was last modified: 02-27-2023, 11:14 PM by Kernelpanic.)
Again to static and dynamic array.
A static array is assigned a fixed, immutable memory location when compiled by the compiler. This can neither be deleted (Erase) nor re-dimensioned. The Erase command just reinitializes the array new with zeros.
In the case of dynamic arrays, the storage space is not determined until the program is running, so it does not have a fixed storage area. Therefore, a dynamic array can also be re-dimensioned with Redim (Erase & Dim): A 4 * 4 array can become a 4 * 6 array, but the dimensions must be observed. A two-dimensional array cannot become a three-dimensional one.
If only the Erase command is applied to a dynamic array, then it no longer exists because it has no a fixed memory area, so it was really deleted, so nothing can be seen anymore.
PS: Note concretized.
A static array is assigned a fixed, immutable memory location when compiled by the compiler. This can neither be deleted (Erase) nor re-dimensioned. The Erase command just reinitializes the array new with zeros.
In the case of dynamic arrays, the storage space is not determined until the program is running, so it does not have a fixed storage area. Therefore, a dynamic array can also be re-dimensioned with Redim (Erase & Dim): A 4 * 4 array can become a 4 * 6 array, but the dimensions must be observed. A two-dimensional array cannot become a three-dimensional one.
If only the Erase command is applied to a dynamic array, then it no longer exists because it has no a fixed memory area, so it was really deleted, so nothing can be seen anymore.
Code: (Select All)
'Static - Dynamic array -- 27. Feb. 2023
Option _Explicit
Dim a(1 To 20)
Dim As Integer z, i
'Dynamisches Feld
Dim As Integer dynamischFeld(20)
Locate CsrLin + 2, 2
Print "Statisches Array"
z = 1
For i = 1 To 20
a(i) = z
Print Using "## "; a(i);
z = z + 1
Next
Erase a
Locate CsrLin + 2, 2
Print "Erase just reinitializes the array"
For i = 1 To 20
Print Using "## "; a(i);
Next
Locate CsrLin + 2, 2
Print "Dynamisches Array"
Locate CsrLin, 2
'Dynamisches Feld initialisieren
z = 1
For i = 1 To 20
dynamischFeld(i) = z
Print Using "## "; dynamischFeld(i);
z = z + 1
Next
Print: Locate , 2
Erase dynamischFeld
Locate CsrLin + 1, 2
'Ergibt Fehlermeldung, da es nicht mehr existiert.
Beep: Print "Error message because the danamic array after Erase no longer exists."
Print Using "## "; dynamischFeld(i);
End
PS: Note concretized.