Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An Array v's A Dictionary
#9
(10-08-2024, 02:46 PM)Dimster Wrote: Oh Ds...another thought just crossed my mind (dangerous I know)

To ReDim a 2 dimensional array ionly works on the 1st index, so ReDim MyArray(1 to x, 1 to 350) is doable whereas ReDim MyArray (1 to 350, 1 to x) doesn't work. Does the use of Dictionary solve this reDimming of multiple dimensional arrays?
Maybe this will help you understand how Redim works. - Neither the type nor the dimension of an array can/may be changed.
There was already a long discussion about this here somewhere.  Rolleyes

PS: Redim only works with dynamic arrays!

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

'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
'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

[Image: Array-neu-dimensionieren08-10-2024.jpg]
Reply


Messages In This Thread
An Array v's A Dictionary - by Dimster - 10-07-2024, 07:18 PM
RE: An Array v's A Dictionary - by bplus - 10-07-2024, 08:03 PM
RE: An Array v's A Dictionary - by TerryRitchie - 10-07-2024, 08:23 PM
RE: An Array v's A Dictionary - by DSMan195276 - 10-08-2024, 02:27 AM
RE: An Array v's A Dictionary - by Dimster - 10-08-2024, 10:26 AM
RE: An Array v's A Dictionary - by DSMan195276 - 10-08-2024, 12:52 PM
RE: An Array v's A Dictionary - by Dimster - 10-08-2024, 02:22 PM
RE: An Array v's A Dictionary - by Dimster - 10-08-2024, 02:46 PM
RE: An Array v's A Dictionary - by Kernelpanic - 10-08-2024, 04:31 PM
RE: An Array v's A Dictionary - by bplus - 10-08-2024, 05:10 PM
RE: An Array v's A Dictionary - by TempodiBasic - 10-08-2024, 06:59 PM



Users browsing this thread: 2 Guest(s)