473,322 Members | 1,352 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,322 software developers and data experts.

how to redeclare an array with different size but keep the previous data?

Tee
Hi,

Anyone know how to redeclare an array with different size but keep the
previous data? Just like the redim preserve in VB.
Thanks.
Nov 16 '05 #1
3 5299

"Tee" <th*@streamyx.com> wrote in message
news:uf**************@TK2MSFTNGP11.phx.gbl...
Hi,

Anyone know how to redeclare an array with different size but keep the
previous data? Just like the redim preserve in VB.


Just create a new array and copy the contents of the old array to it. I
believe thats basically all that ReDim does anyway.
Nov 16 '05 #2
Tee
Hi Dan,

If the redim is needed in a while loop, how should I do it?

Thanks
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eQ**************@TK2MSFTNGP10.phx.gbl...

"Tee" <th*@streamyx.com> wrote in message
news:uf**************@TK2MSFTNGP11.phx.gbl...
Hi,

Anyone know how to redeclare an array with different size but keep the
previous data? Just like the redim preserve in VB.


Just create a new array and copy the contents of the old array to it. I
believe thats basically all that ReDim does anyway.

Nov 16 '05 #3
Tee <th*@streamyx.com> wrote:
If the redim is needed in a while loop, how should I do it?


In exactly the same way. However, you can make things faster by only
reallocating size in chunks - for instance, doubling the size of array
each time, and then reallocating it once after the loop to the "right"
size.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
10
by: Ramprasad A Padmanabhan | last post by:
Hi All, I am a c/perl programmer trying my hand at C++. In my code below I have an array class where I am trying to add two arrays using "+" . I am not sure why I get a '0' always for the first...
16
by: herbertF | last post by:
Hi guys, In a program (not my own) I encountered the declaration of a constant pointer to an array consisting of two other const pointers to arrays. Not quite sure why they do it so complicated,...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
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...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
11
by: cdg | last post by:
Could anyone tell me how to write a loop for an array, that would have to check each iteration for duplications of previous entered values. So, the exact number of loops is not known, but the total...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.