Array Integers vs Array Variables

R

Rob Meade

...
Dim b
b = 10
Dim a(b) ' this errors out but
Dim a() ' this
Redim a(b) ' works

I had exactly the same problem at work a few months back, just used the
redim in the end and it seemed ok - just assumed it was by design...

Rob
 
E

Evertjan.

Roland Hall wrote on 08 feb 2004 in
microsoft.public.inetserver.asp.general:
Dim b
b = 10
Dim a(b) ' this errors out but
Dim a() ' this
Redim a(b) ' works


b = 101
Redim a(b)
response.write ubound(a)

Look, mama, no dims!
 
R

Ray at

True, you must use an actual number when dimming an array, because the array
is put in memory with the Dim statement before any variables are evaluated,
b in this case.
 
R

Roland Hall

In working with arrays, I have found that I am unable to dimension and array
with a variable that has an integer value but I can redimension one this
way. I haven't see any information that tells me if this is a requirement,
although it appears to be because I get an error if I try it.

Ex.

Dim b
b = 10
Dim a(b) ' this errors out but
Dim a() ' this
Redim a(b) ' works


--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
R

Rob Meade

...
I came to the same conclusion so I was looking for some
reasoning other than that's how it works.
ah...

I'm not being facetious.

I know :)
It's nice to know I'm not completely crazy until someone posts with
something I'm missing, I guess.

I wouldn't make those conclusions based on my posts alone Roland :eek:D

Regards

Rob
 
R

Roland Hall

:
: "Roland Hall" wrote...
:
: > Dim b
: > b = 10
: > Dim a(b) ' this errors out but
: > Dim a() ' this
: > Redim a(b) ' works
:
: I had exactly the same problem at work a few months back, just used the
: redim in the end and it seemed ok - just assumed it was by design...

Thanks Rob. I came to the same conclusion so I was looking for some
reasoning other than that's how it works. I'm not being facetious. I
really appreciate the feedback. I just didn't understand why if
redimensioning it works when dimensioning doesn't and have not see any
literature to explain it. It's nice to know I'm not completely crazy until
someone posts with something I'm missing, I guess. (O:=

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
R

Ray at

Roland Hall said:
:'
: True, you must use an actual number when dimming an array, because the
array
: is put in memory with the Dim statement before any variables are
evaluated,
: b in this case.

But I already dimensioned b and it is in memory and I'm just creating a
reference to b, aren't I?


b has been dimmed, but it doesn't have a value yet when the code is
compiled. It doesn't get a value (b=10) until after all the compiling has
finished. Part of the compiling process, as I believe, is making room in
memory for the variables (dim). That, and checking for unterminated
strings, syntax errors, etc. So, if you're the script interpreter, you'd go
to declare an array in memory and see that you should make room for "b"
elements. But you do not know what b is, as you have not yet gotten to the
point at which you start reading lines like "b=10." I guess you could
parallel this logic with why you cannot do <!-- #include
file="<%varName%>" -->. That's a different thing, of course, but the logic
behind why you cannot do it is the same, if that helps at all.

Ray at home
 
R

Roland Hall

:'
: True, you must use an actual number when dimming an array, because the
array
: is put in memory with the Dim statement before any variables are
evaluated,
: b in this case.

But I already dimensioned b and it is in memory and I'm just creating a
reference to b, aren't I?

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
R

Roland Hall

:
: Roland Hall wrote on 08 feb 2004 in
: microsoft.public.inetserver.asp.general:
:
: > Dim b
: > b = 10
: > Dim a(b) ' this errors out but
: > Dim a() ' this
: > Redim a(b) ' works
: >
:
:
: b = 101
: Redim a(b)
: response.write ubound(a)

That's great but that's not my question. My question is, if it was not
clear, why must I use an integer value for Dim when I don't have to for
ReDim.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
E

Evertjan.

Redim is run-time and Dim is compile-time.

I think this is the reason.

But it is only of historical importance since, I think, the difference
between dim and redim could be easily set aside in ASP vbs, and the two
could be made internaly and specification-aly equivalent without any
problem in backward compatibility.

Long ago fixed data memory was set aside in the exe file, to improve speed
at the expence of bigger exe files, because of the strange ways that the
8088/80x86 chip was designed to handle memory.

68000 chip assembler programmers, used to continuous memory adressing,
could only smile.

Perhaps dim and redim are already the same code, only superficially made
different for auld long time sake ?
 
R

Roland Hall

:
: : > "Ray at <%=sLocation%> [MVP]" wrote:'
: > : True, you must use an actual number when dimming an array, because the
: > array
: > : is put in memory with the Dim statement before any variables are
: > evaluated,
: > : b in this case.
: >
: > But I already dimensioned b and it is in memory and I'm just creating a
: > reference to b, aren't I?
:
:
: b has been dimmed, but it doesn't have a value yet when the code is
: compiled. It doesn't get a value (b=10) until after all the compiling has
: finished. Part of the compiling process, as I believe, is making room in
: memory for the variables (dim). That, and checking for unterminated
: strings, syntax errors, etc. So, if you're the script interpreter, you'd
go
: to declare an array in memory and see that you should make room for "b"
: elements. But you do not know what b is, as you have not yet gotten to
the
: point at which you start reading lines like "b=10." I guess you could
: parallel this logic with why you cannot do <!-- #include
: file="<%varName%>" -->. That's a different thing, of course, but the
logic
: behind why you cannot do it is the same, if that helps at all.

Yes, this with your other post that Dim is compile-time and ReDim is
run-time makes sense.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
R

Roland Hall

:
: Redim is run-time and Dim is compile-time.

Ok, so if I:

dim a(4)

and then I

redim(4000)

Memory still has to be set aside for the additional increase. Is memory
used with the initial and then point to the rest additional area or is just
a pointer placed in the original memory location with all of the memory now
stored somewhere else or is the original memory location abandoned once the
redim is run and only the new memory location is used because the original
location is never called again and really doesn't associate with the new
dimension, or does it? That might be the longest question I've ever
written. (O:=

Is there documentation showing how memory is managed with ASP or does it
pass off that handling to something else, like the server or the OS itself?

The reason I'm asking, if that makes a difference is if I better understand
how memory is stored and referenced, it might help me to improve the
performance of my applications.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top