Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REDIM takes more resources than DIM?
#13
Quote:If its completely erased, then why would ReDim not also be able to resurrect a new name for the array? 
@Dimster, it's OK! It took me a while to understand that too; I hope so.  Rolleyes

Deleting with Erase only refers to the memory location of a declared array. Example: twoDimfield. If you now enter: ReDim threeDimfield, what is that supposed to do? The array threeDimfield wasn't even declared.

Code: (Select All)

'Zweidimensionales Feld mit Redim loeschen - 4. Feb. 2024
'Beispiel fuer Anwendung von Erase. Wird Erase auf ein dynamische
'Feld angewendet, existiert das Feld nicht mehr. Bei einem statischen
'Feld wird dieses mit Nullen gefuellt

$Console:Only
Option _Explicit

Option Base 1

Dim As Integer zeilenDim, spaltenDim
Dim As Integer i, j, z, fehlerNummer

On Error GoTo ausserhalbIndex

Locate 2, 2
Input "Feldimension Zeilen  : ", zeilenDim
Locate 3, 2
Input "Felddimension Spalten: ", spaltenDim

'Feld mit Vorgaben initialisieren
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

Locate CsrLin + 2, 2
Print "Redim: ";: Print "Wert von z = "; z

ReDim zweiDimfeld(zeilenDim, spaltenDim)
Locate CsrLin + 2, 2
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

'Ohne Zeile, Spalte bleibt der alte Wert erhalten
ReDim zweiDimfeld(zeilenDim, spaltenDim)

Print: Print "Wert von z neu setzen."
Input "z: ", z

Locate CsrLin + 2, 2
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

Locate CsrLin + 1, 2
Print "Anwendung von ERASE. Feld neu belegen:"
Erase zweiDimfeld

Locate CsrLin + 1, 2
Print "Nach ERASE existiert das Feld nicht mehr."

Locate CsrLin + 1, 2
z = 0
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

'Locate CsrLin + 3, 2
'Error fehlerNummer

'Warum kommt hier eine Fehlermeldung?
ausserhalbIndex:
'If Err = 9 Then Error Err Else Print "Kein Zugriff! Feld existiert nicht mehr."
'Resume Next

End
Reply


Messages In This Thread
REDIM takes more resources than DIM? - by bplus - 07-17-2024, 12:21 AM
RE: REDIM takes more resources than DIM? - by Kernelpanic - 07-17-2024, 01:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Preserving multi-dim arrays Pete 5 440 12-19-2025, 03:17 PM
Last Post: Dimster
  packaging resources tool TempodiBasic 6 601 09-22-2025, 11:16 PM
Last Post: TempodiBasic
  DIM AT -- feature request Jack 2 742 08-15-2023, 12:15 AM
Last Post: grymmjack
  REDIM, TYPE, and STRING Woes TerryRitchie 16 3,222 04-13-2023, 05:17 AM
Last Post: DSMan195276
  suggestion: initialize array values within the DIM statement bobalooie 19 3,425 12-22-2022, 06:46 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)