Jump to content

why is 0 equal to empty string?


Recommended Posts

$var = 0
If $var = "" Then
    MsgBox(0,0,"empty")
EndIf

Why does this code display msgbox? 0 isnt same as "" because with 0 we can still talk about some value, it's 0 but with "" we cant even talk about 0 value because then there's no value.

also msgbox pops up in this code

$var = 0
If $var = false and $var = "" Then
    MsgBox(0,0,"empty")
EndIf
Edited by E1M1

edited

Link to comment
Share on other sites

That is weird... Try using another variable name such as this:

$Variable=0
If $Variable=0 Then
    MsgBox(0,0,"Empty")
Endif

If that doesnt work, then try this.

$Variable=0
Select
    Case $Variable=0
        MsgBox(0,0,"Empty")
EndSelect
Link to comment
Share on other sites

This is normal. Read help file at Language Reference - Datatypes

If you want a strict binary-wise compare, use ==

Also lookup Operators in help.

BTW, 0 is indeed a value, but "" is a value as well: it is an empty string, or put otherwise, a string of length 0.

Several languages or contexts also have a way to denote actual absence of any value (e.g. SQL).

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hahaha I am not quite sure why that worked. You know, when I am in doubt about what a variable is returning, I try something like this.

$Variable=3
Msgbox(0,0,$Variable)

Ofcourse, it would depend on the variale name as to what variable is set as the text. Also, placement in a program is extremely important. Say you want to multiply it by 5, and then figure out if it is multiplying correctly (which would be kinda awkward if it wasnt), then you would have something like this.

$Variable=3
$Variable=$Variable*3 ;Or you could have $Variable*=3 which would do the same
Msgbox(0,0,$Variable)

Also, sometimes, if it is doing complex calculations based on dynamic variables instead of constants, then I would have a messagebox before and after the modifications to see what goes in and what comes out. Sometimes, I even have them inside to see how it is changing the variable as the modifications happen the the value inside the variable. [/Rant] (To relate that back to the topic) However, since your script is faultless, I dont know why it does that. but just to put that idea in your surely brilliant head (If it wasnt already there hahaha), there it is. I used that to check your variable, and it was indeed coming up with 0 on my computer after adding in that little msgbox, like so.

$var = 0
If $var = "" Then
    MsgBox(0,0,"empty")
EndIf
MsgBox(0,0,$var)

Try running that and see what it gives you.

Link to comment
Share on other sites

Why doesn't array get resized?

If Not $tabsdata[uBound($tabsdata) - 1][0] == "" Then This should redim array only if it's last element is not empty.

$tabsdata[uBound($tabsdata) - 1][0] = 0 Gives value to array's last element.

but msgbox doesnt popup. Why?

Dim $tabsdata[1][8]
If Not $tabsdata[UBound($tabsdata) - 1][0] == "" Then
    ReDim $tabsdata[UBound($tabsdata) + 1][8]
EndIf

$tabsdata[UBound($tabsdata) - 1][0] = 0
If Not $tabsdata[UBound($tabsdata) - 1][0] == "" Then
    ReDim $tabsdata[UBound($tabsdata) + 1][8]
    MsgBox(0,0,"Resized")
EndIf

edt it gets resized this way

Dim $tabsdata[1][8]
If Not $tabsdata[UBound($tabsdata) - 1][0] == "" Then
    ReDim $tabsdata[UBound($tabsdata) + 1][8]
    MsgBox(0,0,"Resized")
EndIf

$tabsdata[UBound($tabsdata) - 1][0] = 0
If stringlen($tabsdata[UBound($tabsdata) - 1][0]) > 0 Then
    ReDim $tabsdata[UBound($tabsdata) + 1][8]
    MsgBox(0,0,"Resized")
EndIf
Edited by E1M1

edited

Link to comment
Share on other sites

Beware of operator's precedence!

If Not $tabsdata[uBound($tabsdata) - 1][0] == "" Then

gets parsed as

If (Not $tabsdata[uBound($tabsdata) - 1][0]) == "" Then

while what you're looking for is:

If Not ($tabsdata[uBound($tabsdata) - 1][0] == "") Then

If fact, you probably want something else. Cut&Paste error.

Read: you should also know about UBound parameters.

Try running this:

Dim $tabsdata[1][8]
 ConsoleWrite(UBound($tabsdata, 0) & @LF)
 ConsoleWrite(UBound($tabsdata) & @LF)      ; same as ConsoleWrite(UBound($tabsdata, 1) & @LF)
 ConsoleWrite(UBound($tabsdata, 2) & @LF)
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Then now is as good a time as any to open the help file and study up on the proper usage of And/Or/Not.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...