LurchMan Posted May 10, 2010 Share Posted May 10, 2010 Hey everyone - I'm working on a small inventory script that will find computers by MAC address and S/N. The problem I'm having is when it searches through the excel file if it comes to a cell that has an entry of 0, it returns that as true. Code: Func _Find ($sFilter, $sSearch) Local $aComputerList If $sFilter = "MAC" Then $iColumn = 2 If $sFilter = "SN" Then $iColumn = 1 $aComputerList = _ExcelReadSheetToArray ($oExcel, 3, 1, 0, 0, True) For $i = 1 To $aComputerList[0][0] If $aComputerList[$i][$iColumn] = $sSearch Then Return $aComputerList[$i][0] ;*******Here Next EndFunc I'm not sure why but if $aComputerList[$i][$iColumn] = 0 Then it returns as true...Can someone shed some light on this please? Thanks for any help in advance. 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 More sharing options...
Bowmore Posted May 10, 2010 Share Posted May 10, 2010 (edited) The reason is that if $aComputerList[$i][$iColumn] is a number AutoIt will try to convert $sSearch to a number. If $sSearch does not contain a number it will be converted to 0, hence the comparison will return true. There are several ways to avoid this. Below are some of them. ; == will force a case sensitive string comparison If $aComputerList[$i][$iColumn] == $sSearch Then Return $aComputerList[$i][0] ; force the left hand side to a string and perform a case insensitive string comparison If String($aComputerList[$i][$iColumn]) = $sSearch Then Return $aComputerList[$i][0] ; assuming $sSearch is a string value swaping the left and right hand values should work. If $sSearch = $aComputerList[$i][$iColumn] Then Return $aComputerList[$i][0] ; if you expect the values to be numeric the converting both sides to number type will work If number($aComputerList[$i][$iColumn]) = number($sSearch) Then Return $aComputerList[$i][0] Edit: Fixed autoit tags Edited May 10, 2010 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
LurchMan Posted May 10, 2010 Author Share Posted May 10, 2010 Ok, that makes sense now. I did not know thats how it work - learn something new every day. Thank you for your help with this. 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 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