how to determine if array its empty

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to determine if array its empty

PICCORO McKAY Lenz
i have

 Dim ar As New Variant[]

so how can i determine if the array its empty, i mean does not added any
element.. due that piece of code fails:

If value.dim > 0 Then

If value.count > 0 Then

with a index out of bound exception

Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Gianluigi
Dim myArray As String[]

  If IsNull(myArray) Then Print "Empty"

Regards
Gianluigi

2017-07-01 11:33 GMT+02:00 PICCORO McKAY Lenz <[hidden email]>:

> i have
>
>  Dim ar As New Variant[]
>
> so how can i determine if the array its empty, i mean does not added any
> element.. due that piece of code fails:
>
> If value.dim > 0 Then
>
> If value.count > 0 Then
>
> with a index out of bound exception
>
> Lenz McKAY Gerardo (PICCORO)
> http://qgqlochekone.blogspot.com
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Gianluigi
or
If IsNull(myArray) Or If myArray.Count = 0 Then Print "Empty"

Regards
Gianluigi

2017-07-01 12:09 GMT+02:00 Gianluigi <[hidden email]>:

> Dim myArray As String[]
>
>   If IsNull(myArray) Then Print "Empty"
>
> Regards
> Gianluigi
>
> 2017-07-01 11:33 GMT+02:00 PICCORO McKAY Lenz <[hidden email]>:
>
>> i have
>>
>>  Dim ar As New Variant[]
>>
>> so how can i determine if the array its empty, i mean does not added any
>> element.. due that piece of code fails:
>>
>> If value.dim > 0 Then
>>
>> If value.count > 0 Then
>>
>> with a index out of bound exception
>>
>> Lenz McKAY Gerardo (PICCORO)
>> http://qgqlochekone.blogspot.com
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Gambas-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Cristiano Guadagnino
Hi Gianluigi!

On Sat, Jul 1, 2017 at 12:13 PM, Gianluigi <[hidden email]> wrote:

> or
> If IsNull(myArray) Or If myArray.Count = 0 Then Print "Empty"
>

I have not tried, but I don't think this will work. In an "or" expression
you have to evaluate both members, so if myArray is null the "myArray.Count
= 0" part will generate an out of bounds error.

Cris
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Gianluigi
Hi Cristiano,

Or If is only evaluated if *not* IsNull.

Regards
Gianluigi

2017-07-01 14:08 GMT+02:00 Cristiano Guadagnino <[hidden email]>:

> Hi Gianluigi!
>
> On Sat, Jul 1, 2017 at 12:13 PM, Gianluigi <[hidden email]> wrote:
>
> > or
> > If IsNull(myArray) Or If myArray.Count = 0 Then Print "Empty"
> >
>
> I have not tried, but I don't think this will work. In an "or" expression
> you have to evaluate both members, so if myArray is null the "myArray.Count
> = 0" part will generate an out of bounds error.
>
> Cris
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

PICCORO McKAY Lenz
In reply to this post by Cristiano Guadagnino
2017-07-01 8:08 GMT-04:00 Cristiano Guadagnino <[hidden email]>:

> Hi Gianluigi!
>
> On Sat, Jul 1, 2017 at 12:13 PM, Gianluigi <[hidden email]> wrote:
>
> > or
> > If IsNull(myArray) Or If myArray.Count = 0 Then Print "Empty"
> >
>
> I have not tried, but I don't think this will work. In an "or" expression
> you have to evaluate both members, so if myArray is null the "myArray.Count
> = 0" part will generate an out of bounds error.
>
ahhh! that's the trick!  thanks!


>
> Cris
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Hans Lehmann
In reply to this post by Gianluigi
Hallo,

my idea:

Dim myArray As New String[]

' Existiert das Array und ist die Anzahl der Elemente gleich Null, dann
ist das Array leer
If Not IsNull(myArray) And If myArray.Count = 0 Then Print "Array is empty"

Hans

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Jussi Lahtinen
In reply to this post by Cristiano Guadagnino
If you add the extra "if", then Gambas will do short-circuit evaluation.
https://en.wikipedia.org/wiki/Short-circuit_evaluation


Jussi



On Sat, Jul 1, 2017 at 3:08 PM, Cristiano Guadagnino <[hidden email]>
wrote:

> Hi Gianluigi!
>
> On Sat, Jul 1, 2017 at 12:13 PM, Gianluigi <[hidden email]> wrote:
>
> > or
> > If IsNull(myArray) Or If myArray.Count = 0 Then Print "Empty"
> >
>
> I have not tried, but I don't think this will work. In an "or" expression
> you have to evaluate both members, so if myArray is null the "myArray.Count
> = 0" part will generate an out of bounds error.
>
> Cris
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Hans Lehmann
Correct?

If (Not IsNull(myArray) And myArray.Count = 0) Then Print "Array is empty"

Hans

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Gianluigi
Hi Hans,
If the array is not instantiated or does not work (first example) or does
error.

Regards
Gianluigi

2017-07-01 15:36 GMT+02:00 Hans Lehmann <[hidden email]>:

> Correct?
>
> If (Not IsNull(myArray) And myArray.Count = 0) Then Print "Array is empty"
>
> Hans
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Hans Lehmann

Case 1:
   Dim myArray As String[] --> Array not exist.

Case 2:
   Dim myArray As New String[] --> Array ist empty.

Case 3:
   Dim myArray As New String[] --> Array is not empty!
   myArray.Add("Value")

   If Not IsNull(myArray) Then
      If myArray.Count = 0 Then
         Print "Array ist empty."
      Else
         Print "Array is not empty!"
      Endif
   Else
      Print "Array not exist."
   Endif

Hans

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Gianluigi
Ok, very precise,
depends on what you need.
I think at work, if you have to read the array, an:

If IsNull (myArray) Or If myArray.Count = 0 Then Return

It is more practice

Gianluigi

2017-07-01 16:15 GMT+02:00 Hans Lehmann <[hidden email]>:

>
> Case 1:
>   Dim myArray As String[] --> Array not exist.
>
> Case 2:
>   Dim myArray As New String[] --> Array ist empty.
>
> Case 3:
>   Dim myArray As New String[] --> Array is not empty!
>   myArray.Add("Value")
>
>   If Not IsNull(myArray) Then
>      If myArray.Count = 0 Then
>         Print "Array ist empty."
>      Else
>         Print "Array is not empty!"
>      Endif
>   Else
>      Print "Array not exist."
>   Endif
>
> Hans
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to determine if array its empty

Cristiano Guadagnino
In reply to this post by Jussi Lahtinen
Thank you Jussi, that's a nice trick I didn't know of!
Actually, I didn't even notice there was an extra "if" in Gianluigi's
example.

Cris

On Sat, Jul 1, 2017 at 3:28 PM, Jussi Lahtinen <[hidden email]>
wrote:

> If you add the extra "if", then Gambas will do short-circuit evaluation.
> https://en.wikipedia.org/wiki/Short-circuit_evaluation
>
>
> Jussi
>
>
>
> On Sat, Jul 1, 2017 at 3:08 PM, Cristiano Guadagnino <[hidden email]>
> wrote:
>
> > Hi Gianluigi!
> >
> > On Sat, Jul 1, 2017 at 12:13 PM, Gianluigi <[hidden email]> wrote:
> >
> > > or
> > > If IsNull(myArray) Or If myArray.Count = 0 Then Print "Empty"
> > >
> >
> > I have not tried, but I don't think this will work. In an "or" expression
> > you have to evaluate both members, so if myArray is null the
> "myArray.Count
> > = 0" part will generate an out of bounds error.
> >
> > Cris
> > ------------------------------------------------------------
> > ------------------
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > _______________________________________________
> > Gambas-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Loading...