WeMartiansAreFriendly Posted March 1, 2007 Share Posted March 1, 2007 (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 March 8, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
orange Posted March 1, 2007 Share Posted March 1, 2007 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. Link to comment Share on other sites More sharing options...
jvanegmond Posted March 2, 2007 Share Posted March 2, 2007 What are the advantages over this then just checking if the variable is true, example: $com ="" If $com Then MsgBox(0,"1","$com is empty") $com = "hi" If $com Then MsgBox(0,"2","$com is empty") github.com/jvanegmond Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted March 8, 2007 Author Share Posted March 8, 2007 What are the advantages over this then just checking if the variable is true, example: $com ="" If $com Then MsgBox(0,"1","$com is empty") $com = "hi" If $com Then MsgBox(0,"2","$com is empty") i updated it, see first post. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted March 9, 2007 Author Share Posted March 9, 2007 @ 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() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now