473,903 Members | 3,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8756

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.

"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:iO******** ************@co mcast.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.

"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:iO******** ************@co mcast.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?
"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:E4******** ************@co mcast.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.

"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:iO******** ************@co mcast.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.

"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:iO******** ************@co mcast.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******@bells outh.net> wrote in message
news:0G******** ***********@big news4.bellsouth .net...
Redim the array without using the 'Preserve' keyword. Numeric types will
be
set to zero.

"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:iO******** ************@co mcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?


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

"DazedAndConfus ed" <Ac********@yah oo.com> wrote in message
news:iO******** ************@co mcast.com...
Is there a quick way to fill an array with zeros or make all elements
empty/nothing?

Nov 21 '05 #7
DazedAndConfuse d 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******@bells outh.net> wrote in message
news:0G******** ***********@big news4.bellsouth .net...
Redim the array without using the 'Preserve' keyword. Numeric types will
be
set to zero.

"DazedAndConf used" <Ac********@yah oo.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
"DazedAndConfus ed" <Ac********@yah oo.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**********@G Mail.NOSPAM.com > schrieb:
array.Clear(MyA rray,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

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

Similar topics

4
4750
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 14882:2003(E) §8.5 says:   To zero-initialize an object of type T means: 5   -- if T is a scalar type (3.9), the object is set to the value of 0 (zero) converted to T;
13
27232
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
2502
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 related with the function in C in which the argument's references are passed in the stack during the runtime. I am confused.
25
2712
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 curious to know the use of it.. The code was compiled using Diab C compiler. Also the array was declared in structure like this typedef struct someStruct
26
26261
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 know it's danger to initialize NULL pointers this way. But how about floats? Zhang Le
15
2144
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 <... template<class UnsignedNumericType, std::size_t const i> void SetAllElementsToZero( UnsignedNumericType (&array) ) { memset( array, 0, i * sizeof(UnsignedNumericType) );
14
52496
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 array, and for each iteration, I have to zero out the array. This is how I am currently doing it: // Zero out the lnscores for( count=0; count < chunksize; count++ ) lnscores = 0; Is there no quicker way to do this? I know there must be...
22
2313
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 that it will be evaluated like "x", just as "x" is evaluated like "x" right now.
19
7092
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
2358
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 and which directly go into the Zero Initialised region. We need to cut the size of this ZI region by at least 30%. The one way i see of doing this is by removing these static arrays and passing a pointer to the data structure whenever required....
0
9997
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, 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...
0
9846
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10982
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,...
0
10499
tracyyun
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...
0
7205
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();...
0
6087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4725
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 we have to send another system
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3324
bsmnconsultancy
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...

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.