Sign in to follow this  
Followers 0
WeMartiansAreFriendly

IsEmpty

6 posts in this topic

#1 ·  Posted (edited)

well this is my first post here, but diffenetly not my first UDF..

what this does is check if a variable, or an array is empty e.g. a blank string, kind like what the function IsEmpty in PHP does.

[updated 3/8/2007] i added suggested features, and support to check entire array.

ver 0.2

$z = StringSplit(',,,,k',',')

MsgBox(0,'IsEmpty?',IsEmpty($z[4], 1))

MsgBox(0,'IsEmpty?',IsEmpty($z, 3))

$z = 'hi'
MsgBox(0,'IsEmpty?',IsEmpty($z, 0))

$z = ' '
MsgBox(0,'IsEmpty?',IsEmpty($z, 1))


Func IsEmpty($vVal, $nOpt = 0, $aStart = 1, $aEnd = -1, $srChckStr = '^\s+$')
    ;$nOpt = 0 [default] check if blank
    ;$nOpt = 1 check for $srChckStr ^\s+$ = space,tab,cr,lf,.. (regular expression)
    ;$nOpt = 2 check all values of an array.
    Local $vString = $vVal, $aArray, $x, $y = 1,$vString
    If $nOpt < 0 Or $nOpt > 3 Then Return SetError(1,0,-1)
    If IsArray($vVal) And $nOpt >= 2 Then
        Local $aArray = UBound($vVal) -1, $vString = ''
        If $aStart < 0 Or $aStart > $aArray Then $aStart = 1
        If $aEnd < 0 Or $aEnd > $aArray Then $aEnd = $aArray
        For $x = $aStart To $aEnd Step 1
            $vString &= $vVal[$x]
        Next
    EndIf
    If $nOpt = 0 Or $nOpt = 2 Then
        If ($vString == '') Then Return 1
    ElseIf $nOpt = 1 Or $nOpt = 3 Then 
        If ($vString == '') Or StringRegExp(String($vString),$srChckStr) Then Return 1
    EndIf
    Return 0
EndFunc

ver 0.1

;example
Local $y, $n[3]
If IsEmpty($y) Then Msgbox(0,'Yes','It IsEmpty')
If IsEmpty($n[0]) Then Msgbox(0,'Yes','It IsEmpty')

$n[1] = 'hi'
If IsEmpty($n[1]) Then Msgbox(0,'Yes','It IsEmpty')


Func IsEmpty($vVal)
    If IsArray($vVal) And (Eval($vVal) == '') Then
        Return 1
    ElseIf ($vVal == '') Then 
        Return 1
    EndIf
    Return 0 
EndFunc
Edited by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites



well this is my first post here, but diffenetly not my first UDF..

what this does is check if a variable, or an array is empty e.g. a blank string, kind like what the function IsEmpty in PHP does.

;example
 Local $y, $n[3]
 If IsEmpty($y) Then Msgbox(0,'Yes','It IsEmpty')
 If IsEmpty($n[0]) Then Msgbox(0,'Yes','It IsEmpty')
 
 $n[1] = 'hi'
 If IsEmpty($n[1]) Then Msgbox(0,'Yes','It IsEmpty')
 
 
 Func IsEmpty($vVal)
     If IsArray($vVal) And (Eval($vVal) == '') Then
         Return 1
     ElseIf ($vVal == '') Then 
         Return 1
     EndIf
     Return 0 
 EndFunc
you might want to include an option to have white space ignored as well. " " = $variable is not always useful.

Just a thought.

Share this post


Link to post
Share on other sites

@ mrRevoked

Hi

¿$nOpt = 3?

alc

Share this post


Link to post
Share on other sites

@ mrRevoked

Hi

¿$nOpt = 3?

alc

you combine them, 1+2 = 3 which means check all values in array and check if all the values are blank or contain just the $srChckStr param, which is the space,tab,cr,lf characters by default.

;$nOpt = 0 [default] check if blank
;$nOpt = 1 check for $srChckStr ^\s+$ = space,tab,cr,lf,.. (regular expression)
;$nOpt = 2 check all values of an array.

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0