Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REDIM takes more resources than DIM?
#28
(07-18-2024, 07:51 PM)Pete Wrote: Cool, This is a good point, and something I can't quite off-hand come up with a reason why a variable can be used to avoid a numerically assigned array duplicate definition error...

Code: (Select All)

a = 5
b = 7
' This first half assigns a variable to each array and works.
Dim x(a)
For i = 1 To a: Print i; x(i): Next
Print "-----------------"
ReDim x(b)
For i = 1 To b: Print i; x(i): Next
Print "-----------------"

' This second half assigns numbers to the arrays, and errors out at line 15.
Dim y(5)
For i = 1 To a: Print i; x(i): Next
Print "-----------------"
ReDim y(7)
For i = 1 To b: Print i; x(i): Next
I don't understand what you're trying to say. It's clear that ReDim y(7) produces an error. Dim y(5) doesn't specify a constant value.
That's how it works.

Code: (Select All)

$Console:Only

a = 5
b = 7

' This first half assigns a variable to each array and works.
Dim x(a)
For i = 1 To a: Print i; x(i): Next
Print "-----------------"
ReDim x(b)
For i = 1 To b: Print i; x(i): Next
Print "-----------------"

' This second half assigns numbers to the arrays, and errors out at line 15.
'That's how it works.
y = 5
Dim z(y)
For i = 1 To a: Print i; z(i): Next
Print "-----------------"
ReDim z(b)
For i = 1 To b: Print i; z(i): Next
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-22-2024, 02:34 PM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)