Jas Posted May 11, 2007 Posted May 11, 2007 Heya guys, sorry new user, can't post to the bugs forum. A boolean evaluation appears to be failing on array values if compared between other array values populated with _arrayAdd from a file. I'm fairly certain this is the only (strange) condition that it fails on. Run this, and you'll find that 10 <= 5, but 6,7,8,9 dont suffer the same fate. Note that 10 is the final (contents) value in the array (irrespective of it's value, same error occurs) - arrays Dim'd as [1], and _arrayAdd() upto a size of 11, last index value = [10] obviously... - array index [0] propogated with any data type (or left blank) seems to make no difference. - arrays propogated with _arrayAdd() from a loop $i , or static values, then boolean evaluated seem to work fine. If the array values are cast as a numeric (Int, or probably Number) then the boolean evaluation works correctly. That's all well and good, but normaly the arrays in AutoIt will evaluate numerics against eachother correctly without casting. sample code: CODE#include <Array.au3> Dim $arrayA[1], $arrayB[1] loadFromFile() setVars() main() ;----------------------------------------------- Func main() dim $a = $arrayA[5] ;dim $a = 5 ;_ArrayDisplay($arrayA,"Array A") ;_ArrayDisplay($arrayB,"Array B") For $i = 1 to 10 If $arrayB[$i] <= $a Then MsgBox(0, "uh ohes", $arrayB[$i] & " <= " & $a & " , $i = " & $i) EndIf Next EndFunc ;==>main ;------------------------------------------------- Func loadFromFile() $file = FileOpen("test.txt", 0) ; 0 = read If $file = -1 Then MsgBox(0, "Error", "Unable to open " & "test.txt") Exit EndIf While True $line = FileReadLine($file) If @error = -1 Then ExitLoop _ArrayAdd($arrayA, $line) WEnd FileClose($file) EndFunc ;==>loadFromFile ;---------------------------------------------- Func setVars() For $i = 1 To 10 _ArrayAdd($arrayB, $arrayA[$i]) ;_ArrayAdd($arrayB, $i) Next EndFunc ;==>setVars ;--------------------------
Moderators SmOke_N Posted May 11, 2007 Moderators Posted May 11, 2007 Welcome to the forum... you should have had an issue posting this in the bug forum because guest can post in there from what I can remember... but this was actually the right place to post first, kind of like a "Pre" bug post. When you did the "FileRead()" you are converting it to a string, not a number, so you are comparing "string" values only. Replace this line:If $arrayB[$i] <= $a ThenoÝ÷ Ùh«¢+Ù%9ÕµÈ ÀÌØíÉÉå lÀÌØí¥t¤±Ðìô9ÕµÈ ÀÌØí¤Q¡¸And see if that fixes the issue. Also, next time it would be nice for you to provide everything (including what we are supposed to have in the txt file that is to be read) so we aren't left to assumption. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Jas Posted May 11, 2007 Author Posted May 11, 2007 (edited) Hi Smoke_N, thanks for your reply. I actually just logged in realising I'd forgotten to supply the .txt sample file and discovered your reply. Yes casting the values during the booean evaluation does correct the problem as stated in the intial post. The only reason for pointing it out was that typically AutoIt has been very forgiving(?) with comparing "variants" in the past, and that the sample behaviour is inconsistent in this example, where all values are evaluated correctly EXCEPT the last entry in the array. I've provided the sample .txt file on this post. It's just 1,2,3,4,5,6,7,8,9,10 on their own lines. I dont' actually expect a conclusive solution...just pointing out the anomaly Edited May 11, 2007 by Jas
Moderators SmOke_N Posted May 11, 2007 Moderators Posted May 11, 2007 Hi Smoke_N, thanks for your reply. I actually just logged in realising I'd forgotten to supply the .txt sample file and discovered your reply.Yes casting the values during the booean evaluation does correct the problem as stated in the intial post. The only reason for pointing it out was that typically AutoIt has been very forgiving(?) with comparing "variants" in the past, and that the sample behaviour is inconsistent in this example, where all values are evaluated correctly EXCEPT the last entry in the array.I've provided the sample .txt file on this post. It's just 1,2,3,4,5,6,7,8,9,10 on their own lines.I dont' actually expect a conclusive solution...just pointing out the anomaly Well, "5" does equal "5", I don't understand what you are saying really. Just code it correctly, and use strings as strings, and convert strings to numbers when you are looking for a number value... good coding habits will solve many of your issues.When you take advantage of some of the functions holes to manipulate your code because it does what you want it to do, eventually, those holes are going to get filled and you'll find yourself in a re-coding nightmare. I took advantage of BinaryString() before, and now I'm faced with the same issue, but If I had just done it the "right" way first, I wouldn't be fixing 30 scripts at the moment. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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