beng2beng Posted July 30, 2004 Share Posted July 30, 2004 Hi, in a text file, i have the following items apple orange pear orange apple cherry my routine is: to read each item into an array and within a "for / next" compare each line read to what was already stored and not store a duplicate. Each time I try to compare an array item to a variable within a for / next, it will always return true even though it sees the variable as 0 and or the read line variable and stored variable differ. perhaps a bug? i.e. $thefile = FileOpen("d:\test.txt", 0) $index=1 $match=0 while 1 $line = filereadline($thefile) if @error = -1 then exitloop $i=1 $match=0 for $i=1 to $index if $line=$test[$i] then $match=1 exitloop endif next if $match=0 then $test[$index]=$line $index=$index + 1 endif wend for $i=1 to $index msgbox(0,"Listing of Test",$test[$i],) next fileclose($thefile) Link to comment Share on other sites More sharing options...
beng2beng Posted July 30, 2004 Author Share Posted July 30, 2004 sorry, my copy paste left out 1 line at the very top dim $test[50] thanks Link to comment Share on other sites More sharing options...
CyberSlug Posted July 30, 2004 Share Posted July 30, 2004 Two potential problems:1) Arrays are indexed starting at zero instead of oneTry for $i=0 to $index-12) When you do an equality comparison with a string and an empty array element, the result is always true because a numerical comparsion is used.... You can cast the array element to a string if String($line)=$test[$i] then OR you could make sure your for-loop bounds never compare $line to an empty element. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
beng2beng Posted July 30, 2004 Author Share Posted July 30, 2004 Oh man, thank you!!! I prepped my array with a string filler before storing the items from the file. Should have realized the numerical thingy when everything was resulting in 0. thanks again. Link to comment Share on other sites More sharing options...
trids Posted July 30, 2004 Share Posted July 30, 2004 2) When you do an equality comparison with a string and an empty array element, the result is always true because a numerical comparsion is used.... You can cast the array element to a string if String($line)=$test[$i] then OR you could make sure your for-loop bounds never compare $line to an empty element... OR .. I seem to recall a clever trick (which I haven't had a chance to try yet) .. you can do this: ;Test an array alement for a string value stored in $sTestValue If $sTestValue = "" & $aArrayItem[$nX] HTH 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