#1733 closed Feature Request (Rejected)
IsEmpty function
| Reported by: | Owned by: | Jon | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | Severity: | None | |
| Keywords: | Cc: |
Description
Hello,
Here is a function I find helpful:
; Returns True if value is "empty" (i.e. exists, but no data). Func IsEmpty($value = '') Select Case IsString($value) Return $value == '' Case IsArray($value) Return UBound($value) = 0 Case IsNumber($value) Or IsBinary($value) Or IsPtr($value) Return $value = 0 Case IsBool($value) Return $value = False Case True Return $value ; if don't know the object type, just pass it on EndSelect EndFunc ;==>IsEmpty
It is just a suggestion, thanks!
Attachments (0)
Change History (14)
comment:3 by , on Aug 11, 2010 at 7:58:08 AM
the coding seems a little complicated as the following do the same
Local $a[1]
Local $array = IsEmpty( $a )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $array = ' & $array & @crlf) ;### Debug Console
Local $str = IsEmpty( 'a' )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $str = ' & $str & @crlf) ;### Debug Console
Local $number = IsEmpty(1)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $number = ' & $number & @crlf) ;### Debug Console
Local $bin = IsEmpty( Binary(1) )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bin = ' & $bin & @crlf) ;### Debug Console
Local $ptr = IsEmpty( Ptr(1) )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ptr = ' & $ptr & @crlf) ;### Debug Console
Local $bool = IsEmpty( True )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $bool = ' & $bool & @crlf) ;### Debug Console
Local $keyword = IsEmpty( Default )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $keyword = ' & $keyword & @crlf) ;### Debug Console
Local $emptystr = IsEmpty( '' )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $emptystr = ' & $emptystr & @crlf) ;### Debug Console
Local $emptynumber = IsEmpty(0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $emptynumber = ' & $emptynumber & @crlf) ;### Debug Console
Local $emptybin = IsEmpty( Binary(0) )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $emptybin = ' & $emptybin & @crlf) ;### Debug Console
Local $emptyptr = IsEmpty( Ptr(0) )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $emptyptr = ' & $emptyptr & @crlf) ;### Debug Console
Local $emptybool = IsEmpty( False )
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $emptybool = ' & $emptybool & @crlf) ;### Debug Console
Func IsEmpty($value = '')
If IsString($value) Then
Return $value == ''
Else
Return $value = 0
EndIf
EndFunc
comment:4 by , on Aug 11, 2010 at 6:46:25 PM
Don't know what the general context for the IsEmpty() is. But I think its a ambiguous problem at best. Best solved in relation to the variable/code/target in play at the moment(code location/context).
- There are no empty array's in autoit. A array always has some size.
- Zero as number can be valid data, as such its not empty.
comment:5 by , on Aug 14, 2010 at 7:07:29 AM
| Owner: | set to |
|---|---|
| Status: | new → assigned |
I share mvp remarks, but I leave to other Dev's the final decision oon this request.
comment:6 by , on Aug 23, 2010 at 7:34:15 PM
I'd vote for documenting in the "Operators" section of the help file the difference between "=" and "==". That, other than case-sensitivity, "=" treats a null (empty) string as equal to 0, and "==" does not.
I don't see reason for a Function that replaces 1 or 2 lines of code.
Where's Valik when ya need him? Gong!
comment:7 by , on Aug 24, 2010 at 3:03:58 PM
@Spiff59
I agree "Operators" section can be improved.
Can you suggest the exact change you want to do?
Thanks
comment:8 by , on Aug 25, 2010 at 7:10:23 PM
Well, I don't want to create terminology problems, as I've had two persons argue that, in their opinion, an empty string ("") cannot be called a "null string". They attended to a differnt school than I did. Anyway, I'll aviod using the word null regarding a string, or even referencing Chr(0) as the NUL character. So, Maybe...
The current documentation is:
{{{Language Reference - Operators
Tests if two values are equal (case insensitive if used with strings)
Tests if two values are equal (case sensitive if used with strings)}}}
Would be more informative as:
= Tests if two values are equal (Case-insensitive. Values of 0, "" and Chr(0) are equal) == Tests if two values are equal (Case-sensitive. Values of 0, "" and Chr(0) are not equal)}}} ???
comment:9 by , on Aug 25, 2010 at 9:55:50 PM
Thanks,
I think doc need to be a little more precise as 'a' = 0 is true too
comment:10 by , on Aug 27, 2010 at 8:30:50 AM
Wow! I was completely unaware of that one. And I've of NEVER guessed it would be true unless I'd actually encountered it. I have no idea why that comparison is allowed to test as true. Both ASCII Chr(65) and Chr(97) equal 0? I've never encountered that in any language. It must be that there is some reason for this behavior?
comment:11 by , on Aug 27, 2010 at 4:13:54 PM
From doc:
Language Reference - Datatypes
In AutoIt there is only one datatype called a Variant. A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in. For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings.
But there is no info on ambiguous cases. Like when comparing strings against numbers.
Like with ('a' = 0) -> (number('a') = 0), ('a' = 0) == (0 = 'a').
Seems like "string to number" takes precedence over "number to string" in those cases. (not futher tested)
Something to the effect of:
"In ambiguous (compare?) cases "string to number" is given priority over "number to string" (convertion?)." perhaps.
comment:12 by , on Aug 30, 2010 at 7:51:04 PM
Maybe I was making it too complicated... After all, "" is a string (an empty one), Chr(0) is a string...
Maybe just add to the documentation that:
"Strings equate to 0." for the = operator
And:
"Strings do not equate to 0." for the == operator
?
The documentation currently only mentioning case-sensitivity is incomplete.
comment:13 by , on Aug 31, 2010 at 7:46:04 AM
Doc is OK for string to string comparison.
I think that needs to be improved is the fact that if it is not a string to string then a conversion is done as Number() do.
comment:14 by , on May 22, 2011 at 11:57:40 PM
| Resolution: | → Rejected |
|---|---|
| Status: | assigned → closed |

The last test could also be:
Case True
Return Not $value
I will leave it up to the experts as to which is correct :-)