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

Zero out Array

Is there a quick way to fill an array with zeros or make all elements
empty/nothing?
Nov 21 '05 #1
13 8682

it depends.

specifying the array dimensions in the dim should fill it based on your
requirements.

dim intArray(5) as integer ' elements s/b 0
dim objArray(5) as string ' elements s/b nothing

but then again, i assume you just haven't fleshed out your question
completely.

you can erase arrays, set variables to new arrays, initialize arrays,
etc....it really depends on what it is you're trying to accomplish.

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
| Is there a quick way to fill an array with zeros or make all elements
| empty/nothing?
Nov 21 '05 #2
Your right I didn't give an accurate description of what I am doing.

The array is dimensioned as Shared Friend.
The elements are populated with data and processed.
The array needs to be emptied out before reloading with new data without
redimensioning.

I know I can use for loops to reset the array, but I was looking to see if
there is a better way. I will look to see what erase array offers. Let me
know if there is a better way.

Thank You.
"" <a@b.com> wrote in message news:j4******************@fe07.lga...
it depends.

specifying the array dimensions in the dim should fill it based on your
requirements.

dim intArray(5) as integer ' elements s/b 0
dim objArray(5) as string ' elements s/b nothing

but then again, i assume you just haven't fleshed out your question
completely.

you can erase arrays, set variables to new arrays, initialize arrays,
etc....it really depends on what it is you're trying to accomplish.

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
| Is there a quick way to fill an array with zeros or make all elements
| empty/nothing?

Nov 21 '05 #3
ReDim appears to be giving me the result I wanted, but I am unsure if this
is the proper way because I am not really changing dimension sizes. Should I
also be erasing the array before I ReDim?
"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:E4********************@comcast.com...
Your right I didn't give an accurate description of what I am doing.

The array is dimensioned as Shared Friend.
The elements are populated with data and processed.
The array needs to be emptied out before reloading with new data without
redimensioning.

I know I can use for loops to reset the array, but I was looking to see if
there is a better way. I will look to see what erase array offers. Let me
know if there is a better way.

Thank You.
"" <a@b.com> wrote in message news:j4******************@fe07.lga...
it depends.

specifying the array dimensions in the dim should fill it based on your
requirements.

dim intArray(5) as integer ' elements s/b 0
dim objArray(5) as string ' elements s/b nothing

but then again, i assume you just haven't fleshed out your question
completely.

you can erase arrays, set variables to new arrays, initialize arrays,
etc....it really depends on what it is you're trying to accomplish.

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
| Is there a quick way to fill an array with zeros or make all elements
| empty/nothing?


Nov 21 '05 #4
Redim the array without using the 'Preserve' keyword. Numeric types will be
set to zero.

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?

Nov 21 '05 #5
Thank you. I get sooo confused with VS Help. ReDim is working great. Help
says "ReDim creates another new array" and I am afraid I am creating
multiple arrays when I only need 1. Just trying not to write crappy code!

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:0G*******************@bignews4.bellsouth.net. ..
Redim the array without using the 'Preserve' keyword. Numeric types will
be
set to zero.

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?


Nov 21 '05 #6
array.Clear(MyArray,0,MyArray.Length)

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?

Nov 21 '05 #7
DazedAndConfused wrote:
Thank you. I get sooo confused with VS Help. ReDim is working great. Help
says "ReDim creates another new array" and I am afraid I am creating
multiple arrays when I only need 1. Just trying not to write crappy code!

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:0G*******************@bignews4.bellsouth.net. ..
Redim the array without using the 'Preserve' keyword. Numeric types will
be
set to zero.

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?




AFAIK, redim will create you another array, but then the first array
will be cleaned up by the garbage collector when it gets around to it
and no other object reference the array.

Chris
Nov 21 '05 #8
"DazedAndConfused" <Ac********@yahoo.com> schrieb:
Thank you. I get sooo confused with VS Help. ReDim is working great. Help
says "ReDim creates another new array" and I am afraid I am creating
multiple arrays when I only need 1.


Yes, 'ReDim' will create a new array. However, the old array will be
transparently removed from memory by the garbabe collector automatically.
Alternatively you could loop through the array and reset all the items in
the array (three lines of code...).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
"Rick Mogstad" <Ri**********@GMail.NOSPAM.com> schrieb:
array.Clear(MyArray,0,MyArray.Length)


That's indeed a good solution!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #10
I have a multi-dimensional array, would I need to:

array.Clear(MyArray,0,MyArray.Length)
array.Clear(MyArray,1,MyArray.Length)
array.Clear(MyArray,2,MyArray.Length)
array.Clear(MyArray,3,MyArray.Length)

?

"Rick Mogstad" <Ri**********@GMail.NOSPAM.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
array.Clear(MyArray,0,MyArray.Length)

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?


Nov 21 '05 #11
OK, Length is the total size of the array including all dimensions. So
starting at 0 and going to Length would clear all dimensions.

Do I have that right?

Thank you again.
"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:d7********************@comcast.com...
I have a multi-dimensional array, would I need to:

array.Clear(MyArray,0,MyArray.Length)
array.Clear(MyArray,1,MyArray.Length)
array.Clear(MyArray,2,MyArray.Length)
array.Clear(MyArray,3,MyArray.Length)

?

"Rick Mogstad" <Ri**********@GMail.NOSPAM.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
array.Clear(MyArray,0,MyArray.Length)

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?



Nov 21 '05 #12
Hmm. Probably, you would have to try it out. I dont use multi-dimensional
arrays much, so I havent tried it.
"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:Mu********************@comcast.com...
OK, Length is the total size of the array including all dimensions. So
starting at 0 and going to Length would clear all dimensions.

Do I have that right?

Thank you again.
"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:d7********************@comcast.com...
I have a multi-dimensional array, would I need to:

array.Clear(MyArray,0,MyArray.Length)
array.Clear(MyArray,1,MyArray.Length)
array.Clear(MyArray,2,MyArray.Length)
array.Clear(MyArray,3,MyArray.Length)

?

"Rick Mogstad" <Ri**********@GMail.NOSPAM.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
array.Clear(MyArray,0,MyArray.Length)

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?



Nov 21 '05 #13
It seems to be working. Thank you.
"Rick Mogstad" <Ri**********@GMail.NOSPAM.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
Hmm. Probably, you would have to try it out. I dont use
multi-dimensional arrays much, so I havent tried it.
"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:Mu********************@comcast.com...
OK, Length is the total size of the array including all dimensions. So
starting at 0 and going to Length would clear all dimensions.

Do I have that right?

Thank you again.
"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:d7********************@comcast.com...
I have a multi-dimensional array, would I need to:

array.Clear(MyArray,0,MyArray.Length)
array.Clear(MyArray,1,MyArray.Length)
array.Clear(MyArray,2,MyArray.Length)
array.Clear(MyArray,3,MyArray.Length)

?

"Rick Mogstad" <Ri**********@GMail.NOSPAM.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
array.Clear(MyArray,0,MyArray.Length)

"DazedAndConfused" <Ac********@yahoo.com> wrote in message
news:iO********************@comcast.com...
> Is there a quick way to fill an array with zeros or make all elements
> empty/nothing?
>



Nov 21 '05 #14

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

Similar topics

4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
13
by: simondex | last post by:
Hi, Everyone! Does anyone know how to initialize an int array with a non-zero number? Thank You Very Much. Truly Yours, Simon Dexter
14
by: dam_fool_2003 | last post by:
Hai, When I declare a zero-based array I get a compile time error stating that zero based array is not possible. But if I declare the same in the function argument I don't get any error. Is...
25
by: prashna | last post by:
Hi all, I have seen a piece of code(while doing code review) which declared an array of size 0.One of my friend told although it is not standard C,some compilers will support this..I am very...
26
by: 69dbb24b2db3daad932c457cccfd6 | last post by:
Hello, I have to initialize all elements of a very big float point array to zero. It seems memset(a, 0, len) is faster than a simple loop. I just want to know whether it is safe to do so, since I...
15
by: Tomás | last post by:
Is the following fully legal and fully portable for all the unsigned types? The aim of the function is to take an array by reference and set each element's value to zero. #include <... ...
14
by: rocketman768 | last post by:
Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this...
22
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest...
19
by: nileshsimaria | last post by:
Hi, I have seen some code were we have array with zero elements (mostly within structure) like, typedef struct foo { int data }foo;
37
by: Ajai Jose | last post by:
Hi , I work on an ARM processor based embedded system. Code is mainly in C language. The project has a huge source base. We are supposed to optimise it. Most datastructures are declared as static...
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...
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.