473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Array Integers vs Array Variables

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
Jul 19 '05 #1
16 1784
"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...

Rob
Jul 19 '05 #2
"Rob Meade" wrote:
: "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
Jul 19 '05 #3
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!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #4
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.

--

Ray at home
Microsoft ASP MVP
"Roland Hall" <nobody@nowhere> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
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

Jul 19 '05 #5
My Mom would yell at me if I didn't Dim. And she'd be right in doing so!

--

Ray at home
Microsoft ASP MVP
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.20...

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

Look, mama, no dims!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 19 '05 #6
Ray at <%=sLocation%> [MVP] wrote on 08 feb 2004 in
microsoft.public.inetserver.asp.general:
My Mom would yell at me if I didn't Dim.
And she'd be right in doing so!


She must have a dim view of you.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #7

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.20...
Ray at <%=sLocation%> [MVP] wrote on 08 feb 2004 in
microsoft.public.inetserver.asp.general:
My Mom would yell at me if I didn't Dim.
And she'd be right in doing so!


She must have a dim view of you.


I am a multidimensional Ray, as she dimmed me to be.

Ray at home
Jul 19 '05 #8
"Evertjan." wrote ...
She must have a dim view of you.


baadoom-tish! :o)

Rob
Jul 19 '05 #9
"Roland Hall" wrote...
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 :oD

Regards

Rob
Jul 19 '05 #10
"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?

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

Jul 19 '05 #11
"Evertjan." wrote:
: 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
Jul 19 '05 #12
Redim is run-time and Dim is compile-time.

Ray at home

"Roland Hall" <nobody@nowhere> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...

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

Jul 19 '05 #13

"Roland Hall" <nobody@nowhere> wrote in message
news:OB**************@TK2MSFTNGP11.phx.gbl...
"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.

Ray at home
Jul 19 '05 #14
"Ray at <%=sLocation%> [MVP]" wrote:
: "Roland Hall" <nobody@nowhere> wrote in message
: news:OB**************@TK2MSFTNGP11.phx.gbl...
: > "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
Jul 19 '05 #15
"Ray at <%=sLocation%> [MVP]" wrote:
: 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
Jul 19 '05 #16
Ray at <%=sLocation%> [MVP] wrote on 08 feb 2004 in
microsoft.public.inetserver.asp.general:
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 ?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
4569
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
20
2900
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
7
2673
by: Rajeev | last post by:
Hello, I'm using gcc 3.4.2 on a Xeon (P4) platform, all kinds of speed optimizations turned on. For the following loop R=(evaluate here); // float N=(evaluate here); // N min=1 max=100...
41
2180
by: puzzlecracker | last post by:
Given an array of size n and populated with consecutive integers from 1 to n i.e. in random order. Two integers are removed, meaning zero is placed in their places. Give O (n) efficient algorithm...
5
2065
by: jar13861 | last post by:
I'm confused on how to write a random array that will only generate 9 different numbers from 1-9. Here is what I have, but its only writing one number.... holder = new Array ( 9 ); var flag =...
25
5834
by: Jessica Weiner | last post by:
I have an array of n integers and I want a function that returns a list of arrays of all possible subsets. Can someone provide me with the code? Thanks. Jess
8
12944
by: Jim | last post by:
In a C# project I'm working on for an iterative design application, I need to dispose of a large arrray of a struct object and reinitialize the array between iterations. That is, the user starts...
49
2140
by: David | last post by:
I need to do an array with around 15000 integers in it. I have declared it as unsigned letter; But the compiler is saying that this is too much. How can I create an array for 15000 integers? I...
1
9873
by: mattmao | last post by:
Hello everyone, this is my first thread in this .NET forum. Since I am studying C#.NET in this semester, I reckon this would be just the right place for my asking questions regarding the C#...
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.