Jump to content

Variable Comparing


Recommended Posts

Hello all - 

I don't need any help with a script this time just help explaining a snippet:

Local $Array[3] = [0, 1, ""]

For $i = 0 To UBound ($Array) - 1

    If $Array[$i] <> "" Then
        ConsoleWrite ('Value of array: ' & $Array[$i] & ' $Array[' & $i & '] is not ""' & @CRLF)
    Else
        ConsoleWrite ('Value of array: ' & $Array[$i] & ' $Array[' & $i & '] is ""' & @CRLF)
    EndIf

Next

Output:

Value of array: 0 $Array[0] is ""
Value of array: 1 $Array[1] is not ""
Value of array:  $Array[2] is ""

 

 

 
 

I understand why 0 gets translated as not <> "" as all three (0, "", False) would be translated as false.   Now the question - Is there a more standardized way to deal with these situations?  

I have a section of a script that would fill in an array and do compares similar to the one above and it was checking to see if an element had data in it.  Some of the data would be 0 and comparing it to "" would always return as True as seen above.  I obviously got around this by comparing the element to -1 instead of "" as all the data in this case was numerical but is there a better way to achieve this?

I apologize if this isn't well written, my thoughts are all over the place on this one.  Thanks for any thoughts in advance.

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Ok, that makes a little more sense.  Thank you for your help!

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

One more possibility between "just declared" and set to either 0 or empty string: explicitely initialize your variable(s) to Null. Requires recent enough AutoIt.

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

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...