473,399 Members | 3,832 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,399 software developers and data experts.

Simple Array Question

Hi Guys,

I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those who experience.
(For some reason I have to implement Array not ArrayLists)
Below are the simple following code:

Dim Array() As String
Dim intCounter As Integer
Array = strRESP.Split(",") ' <-- insert value which is comma
deliminated
............ ' It has been working then I would like to clear the array
............

For intCounter = 0 To Array.Length - 1
Array.Clear(intCounter) ' <-- This doesn't work out
'Array(intCounter).Clear() <-- This method doesn't work
either
Next

Do you guys have any solution/ recommendation to clear those array
lists?

I really appreciate all of your input.

Jun 22 '06 #1
4 1502
I tried "Array.Clear()" doesn't work either
Armand wrote:
Hi Guys,

I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those who experience.
(For some reason I have to implement Array not ArrayLists)
Below are the simple following code:

Dim Array() As String
Dim intCounter As Integer
Array = strRESP.Split(",") ' <-- insert value which is comma
deliminated
........... ' It has been working then I would like to clear the array
...........

For intCounter = 0 To Array.Length - 1
Array.Clear(intCounter) ' <-- This doesn't work out
'Array(intCounter).Clear() <-- This method doesn't work
either
Next

Do you guys have any solution/ recommendation to clear those array
lists?

I really appreciate all of your input.


Jun 22 '06 #2
You don't clear arrays.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.

"Armand" <ar*************@gmail.com> wrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
Hi Guys,

I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those who experience.
(For some reason I have to implement Array not ArrayLists)
Below are the simple following code:

Dim Array() As String
Dim intCounter As Integer
Array = strRESP.Split(",") ' <-- insert value which is comma
deliminated
........... ' It has been working then I would like to clear the array
...........

For intCounter = 0 To Array.Length - 1
Array.Clear(intCounter) ' <-- This doesn't work out
'Array(intCounter).Clear() <-- This method doesn't work
either
Next

Do you guys have any solution/ recommendation to clear those array
lists?

I really appreciate all of your input.

Jun 22 '06 #3
What do you mean by clearing the array?

If you want to set every value in the array to Nothing, the Clear method
works. You call it like this:

Array.Clear(theArray, 0, theArray.Length)

If you want to get rid of the entire array, just set the reference to
Nothing:

theArray = Nothing
Armand wrote:
Hi Guys,

I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those who experience.
(For some reason I have to implement Array not ArrayLists)
Below are the simple following code:

Dim Array() As String
Dim intCounter As Integer
Array = strRESP.Split(",") ' <-- insert value which is comma
deliminated
........... ' It has been working then I would like to clear the array
...........

For intCounter = 0 To Array.Length - 1
Array.Clear(intCounter) ' <-- This doesn't work out
'Array(intCounter).Clear() <-- This method doesn't work
either
Next

Do you guys have any solution/ recommendation to clear those array
lists?

I really appreciate all of your input.

Jun 22 '06 #4
In either case, it doesn't matter. An array is immutable. So, it is either
referenced or not. Once you create an array, you can neither make it shorter
or longer. Setting it to a null (Nothing) value has the same effect as
de-referencing it. For example:

Dim aryStrings() As String = {"Short", "Lived", "Array"}
aryStrings = {"Some", "New", "Array"}

What you have done here is not to replace the elements in the array, but to
de-reference the first array by assigning a new array to the variable. On
the other hand,

aryStrings(0) = "Another"

only replaces the string in the first element of the array.

By the same token:

Dim aryStrings(3) As String()

creates an array of 3 elements. When you write

aryStrings = New String(4)

de-references the original array of 3 elements and replaces it with a new
array of 4 elements.

Now, the Clear method of the Array class is a static (Shared) method, which
is invoked without a reference to the array itself, except as a parameter:

Array.Clear(aryStrings, 0, 4)

does not shorten the array. It simply sets the members of the array to null
values (Nothing). The array is still 4 elements in length.

When the de-referenced array which the variable used to reference is
de-referenced by assigning another array to the variable, it is cleaned up
from memory, regardless of whether you set it to Nothing or not. An array
(or anything else) can also be de-referenced by passing out of scope, as in:

Private Sub ReplaceFirst(Integer i)
Dim aryIntegers as { 0, 1, 2 }
aryIntegers(0) = i
End Sub

As soon as the Sub exits, the array created inside it is de-referenced and
cleared from the stack. The same thing will happen if, for an example, a
class has a member that is an Array, and the class is de-referenced. Since
the Array was a member of the class, and the class is de-referenced, the
Array is also de-referenced.

Only Collections can be resized.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

I recycle.
I send everything back to the planet it came from.
"Göran Andersson" <gu***@guffa.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
What do you mean by clearing the array?

If you want to set every value in the array to Nothing, the Clear method
works. You call it like this:

Array.Clear(theArray, 0, theArray.Length)

If you want to get rid of the entire array, just set the reference to
Nothing:

theArray = Nothing
Armand wrote:
Hi Guys,

I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those who experience.
(For some reason I have to implement Array not ArrayLists)
Below are the simple following code:

Dim Array() As String
Dim intCounter As Integer
Array = strRESP.Split(",") ' <-- insert value which is comma
deliminated
........... ' It has been working then I would like to clear the array
...........

For intCounter = 0 To Array.Length - 1
Array.Clear(intCounter) ' <-- This doesn't work out
'Array(intCounter).Clear() <-- This method doesn't work
either
Next

Do you guys have any solution/ recommendation to clear those array
lists?

I really appreciate all of your input.

Jun 23 '06 #5

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

Similar topics

18
by: Geoff Cox | last post by:
Hello, I am trying to print out the array values for a second time but get error on page message? Thanks Geoff <html>
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
2
by: purna chandra | last post by:
Hello, I have a simple question.Hoping not to take much of your valuable time...:-). I am trying to get the data from a string, and am wondering if I get...
1
by: number1.email | last post by:
Hello, I have a simple Web Page Questionairre in which questions are read from a database, and the user can indicate the correct answer via either a radio input control or a dropdown list. The...
27
by: karan.shashi | last post by:
Hey all, I was asked this question in an interview recently: Suppose you have the method signature bool MyPairSum(int array, int sum) the array has all unique values (no repeats), your...
23
by: AndersWang | last post by:
Hi, dose anybody here explain to me why memset would be faster than a simple loop. I doubt about it! In an int array scenario: int array; for(int i=0;i<10;i++) //ten loops
4
by: sam | last post by:
hI, I am little confused here See i have int wordlen=10; when int s is array s++; whats the meaning of this
6
by: Ronald Raygun | last post by:
I want to be able to randomly select the following from an array: 1). An image 2). A piece of text (name of tge image) 3). A piece of text (description of the image) I want to be able to...
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?
0
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.