473,761 Members | 4,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(int Counter) ' <-- This doesn't work out
'Array(intCount er).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 1522
I tried "Array.Clea r()" 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(int Counter) ' <-- This doesn't work out
'Array(intCount er).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******** *************@p 79g2000cwp.goog legroups.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(int Counter) ' <-- This doesn't work out
'Array(intCount er).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(the Array, 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(int Counter) ' <-- This doesn't work out
'Array(intCount er).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(ary Strings, 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(In teger 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.co m> wrote in message
news:%2******** ********@TK2MSF TNGP02.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(the Array, 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(int Counter) ' <-- This doesn't work out
'Array(intCount er).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
1810
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
8288
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 code? many thx!
8
5113
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 types or std::vector<int>. So where I would use an int* and reallocate it from time to time in C, and randomly access it via , then I figure to copy the capacity and reserve methods, because I just need a growable array. I get to considering...
2
1473
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 http://groups.google.com/intl/en/googlegroups/tour/index.html from the array : array('c', '\x00=http://groups.google.com/intl/en/googlegroups/tour/index.html')) Thanks in advance,
1
1464
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 number of questions that is displayed on the screen can vary...depending on the number of questions that satisfy certain criteria. Does anyone have any sample code, or can show me how I can validate this Web Page in JavaScript so that the user is...
27
1849
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 task is to find two
23
13330
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
1884
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
1675
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 build a static array with the values hardcoded into the array, and then be able to randomly select an item from the array and retrieve the image, name and description.
0
9538
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
10123
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, 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...
0
9788
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
8794
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
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 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...
0
6623
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
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3889
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
3
2765
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.