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 2 4756
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"
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******@NOyah oo.SPAMcom> wrote in message
news:eW******** ******@TK2MSFTN GP11.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"
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 issue in
another thread and I have received an answer that works (code is
below)
However, my test data thus far has been in the 10-50MB size range. I
now have a case where the text file is 650MB in size!
I need to convert it to ANSI for my...
|
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 statement in VB does this. Is
there an equivalent in C#?
|
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
|
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 changed).
|
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 Contains
property before adding.
Question. Can I use an Array for this or should I use an
| |
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 Preserve SomeArray(c)
SomeArray(c) = SomeObject
<end loop>
|
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 than in .Net environment, under VS 2005 Beta 2. Does anyone
have any idea whether this will be addressed in the final release?
Thanks,
Tomasz
|
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", ",")
|
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 SyncLock ArrayName.SyncRoot
at the beginning of the Sub and an End SyncLock at the end. But this caused
the application to produce no output (an Excel spreadsheet)! After some
screwing around, sorry ... I mean experimenting, I noticed that the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |