By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

Newbee: questions on array

P: n/a
Hi all,

can anyone tell me how i can find out if an array is empty?
i want to code an if statment that loops through an array only if it is not empty.
I have been trying
if not (CarArray1 is nothing) then

but this doesnt work. I was told to use the count, but it doesnt like my coding
if CarArray1.count >0 then

Can anyone advise me?

Also, How do i clear the items in an array?
CarArray1.clear ????

As u can see i just guessing the coding :o)
thank u

Nov 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cor
Hi Varun,

I thought a array can never be empty only if you declare it as
dim myarray() as array
But then it is almost useless.

But mostly you can see if there are no items in an array with

if myarray.length = 0

In the above example this wil throw an error

If you have declared it as
dim myarray() as array = {} than it had given the result you want.

In the first situation, you could have done

If myarray Is Nothing because there was no array.

But in my opinion is with this type of arrays this is useless coding,
because you know the length of the array.

So look what type of array you use and when you want it dynamical, have a
look for "arraylist".

I hope this helps,
can anyone tell me how i can find out if an array is empty?
i want to code an if statment that loops through an array only if it is not empty.
I have been trying
if not (CarArray1 is nothing) then

but this doesnt work. I was told to use the count, but it doesnt like my coding if CarArray1.count >0 then

Can anyone advise me?

Also, How do i clear the items in an array?
CarArray1.clear ????

As u can see i just guessing the coding :o)
thank u

Nov 22 '05 #2

P: n/a
I have declared my array with coding from example from the interne
Dim CarArray(10) As strin

What i have done is added the values to my array
i.e Mustang, Ford etc
What i want is to now remove all the values that are in my array when user clicks a button

Is this not possible
What is difference between arraylist and normal array. I asked my friend and he said there is no difference!?

Thank you for help

Nov 22 '05 #3

P: n/a
Cor
Hi Varun,

Here a very small sample
\\\
Dim myArray As New ArrayList
myArray.Add("Peugeot")
myArray.Add("Ferari")
myArray.Add("Fiat")
myArray.Add("Renault")
myArray.RemoveAt(0)
myArray.Insert(1, "Mercedes")
myArray.Clear()
///

I hope this helps,

Cor
Nov 22 '05 #4

P: n/a
Thank you for coding example. this is very kind of you. I will try it and read up on arraylist. If i have any difficulties i will message back again
Nov 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.