473,385 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

redim preserve myArray(i)

Is it correct to think that after reducing the populated array's size from
say, 10 to 5 with
redim preserve myArray(i)
an attempt to access an element above the fifth does not cause a
compillation error "array out of script", but returns whatever heppened to
be written in that memory address (in particular it might return the correct
values of those elements before re-dimentioning)?
This seems to be the case in my code, yet I wanted to make sure that this is
not the result of some other side effect
Jul 19 '05 #1
2 4731
aa wrote:
Is it correct to think that after reducing the populated array's size
from say, 10 to 5 with
redim preserve myArray(i)
an attempt to access an element above the fifth does not cause a
compillation error "array out of script", but returns whatever
heppened to be written in that memory address (in particular it might
return the correct values of those elements before re-dimentioning)?
This seems to be the case in my code, yet I wanted to make sure that
this is not the result of some other side effect


Nope. As expected, this code raises the "Subscript out of range: '5'" error
on my machine:

<%
dim ar(),i
redim ar(10)
for i=0 to 10
ar(i)=1
next
redim preserve ar(4)
Response.Write ar(5)
Response.End
%>

If you are using "on error resume next", and you attempt to redim an array
that cannot be redim'ed (the only redimmable arrays are those declared with
the syntax shown in my dim statement above), you may not receive the error
message, and the array will be unaffected by the redim statement. That is
what happens when I change my code to this:

<%
on error resume next
dim ar(10), i
for i=0 to 10
ar(i)=i
next
redim preserve ar(4)
for i = 0 to 10
Response.Write ar(i) & "<BR>"
next
Response.End
%>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2
Thans, Bob, that's exactly what I wanted to know.
My code redims an array up and down and thought it does not produce an
error, sometimes the final result is incorrect.
So I have an error elsewhere

"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
aa wrote:
Is it correct to think that after reducing the populated array's size
from say, 10 to 5 with
redim preserve myArray(i)
an attempt to access an element above the fifth does not cause a
compillation error "array out of script", but returns whatever
heppened to be written in that memory address (in particular it might
return the correct values of those elements before re-dimentioning)?
This seems to be the case in my code, yet I wanted to make sure that
this is not the result of some other side effect
Nope. As expected, this code raises the "Subscript out of range: '5'"

error on my machine:

<%
dim ar(),i
redim ar(10)
for i=0 to 10
ar(i)=1
next
redim preserve ar(4)
Response.Write ar(5)
Response.End
%>

If you are using "on error resume next", and you attempt to redim an array
that cannot be redim'ed (the only redimmable arrays are those declared with the syntax shown in my dim statement above), you may not receive the error
message, and the array will be unaffected by the redim statement. That is
what happens when I change my code to this:

<%
on error resume next
dim ar(10), i
for i=0 to 10
ar(i)=i
next
redim preserve ar(4)
for i = 0 to 10
Response.Write ar(i) & "<BR>"
next
Response.End
%>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #3

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

Similar topics

4
by: Trevor Fairchild | last post by:
I've got a program that parses text files. The text files come to me in Unicode and they contain goofy characters that VB chokes on - treats them as eof markers. I have already been through this...
7
by: mb | last post by:
I have an array that starts with 99 index. I use a random amount of the indexes, let's say 23. Is there a way to truncate the array to 23 elements while preserving the 23 used? The ReDim...
6
by: LP | last post by:
Hello, What is C# equivalent of rediming an array and preserving exciting elements. VB.NET syntax looks something like this: ReDim Preserve myArray(5) Thank you
6
by: John Grandy | last post by:
Does C# have an equivalent for VB.NET's Redim Preserve ? ReDim Preserve increases the final dimension of any array while preserving the array's contents (however, the type of the array may not be...
5
by: Zenobia | last post by:
Hello, I want to keep a list references to database records being accessed. I will do this by storing the record keys in a list. The list must not contain duplicate keys. So I check the...
5
by: Paul | last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding items to an array than redim preserve? Paul <begin loop> Dim c As Integer = SomeArray.GetUpperBound(0) + 1 ReDim...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
1
by: Freddy Coal | last post by:
Hi, I don't know how redim an array, My problem whit an example: I define my array Dim Ary as array I put three elements inside my array Ary = Split("one,two,three", ",")
2
by: eBob.com | last post by:
I was changing some code in a multi-threaded application today and noticed that it was not locking where it really needed to be locking. The Sub was already working with an array so I just stuck a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.