Newbee: questions on array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 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
 
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
 
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
 
Back
Top