4b0082 Posted November 11, 2014 Share Posted November 11, 2014 (edited) I'm not really sure what's causing this script to break; it seems to be working perfectly and then after running for some time the $a variable and my first If/Then statement quit functioning appropriately. Snippet of script (nested in another while loop to keep it cycling). $a = 0 $b = 0 $c = 10 While $b <> UBound($Items) While $b <> $c If $Items[$b][1] < $tArray[$a][1] Then If _ArrayFindAll($dupes, $Items[$b][1]) = -1 Then _ArrayAdd($dupes, $Items[$b][1]) $Open = MsgBox(4, "Item Found", "Item: " & $Items[$b][2] & @LF & "Price: $" & $Items[$b][1]) If $Open = 6 Then $iPage = $Items[$b][0] ShellExecute($iPage) EndIf EndIf EndIf $b += 1 WEnd $c += 10 $a += 1 WEnd For some reason, my statement "If $Items[$b][1] < $tArray[$a][1] Then" is processing "If 24.95 < 4 Then" as a true value. $a SHOULD be pulling from the array as $tArray[3][1] which is a value of 20, but it's instead processing as $tArray[2][1], which is the value of 4. $Items is an array of 40 (0-39), $tArray is an array of 4 (0-3). Any idea what's causing this loop to break? Edited November 11, 2014 by 4b0082 Link to comment Share on other sites More sharing options...
Jfish Posted November 11, 2014 Share Posted November 11, 2014 Are all your values numeric? Strings won't evaluate properly. You can cast them to numbers to be sure. Also, the whole code would be more helpful. Finally, I would suggest some debugging to measure all the values along the way and check for errors. 4b0082 1 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
4b0082 Posted November 11, 2014 Author Share Posted November 11, 2014 All of my values are numeric, and I tried to troubleshoot but I still don't really know what's causing the issue. $a += 1 is definitely working, but the script is breaking before reaching that point and my If/Then is still processing "If 20 < 4 Then" as a true statement. I was kind of hoping to avoid posting my whole script, though. Is there more specific information I can provide to avoid posting the whole thing? Do you think rewriting this part of the code in a different way might help? Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted November 11, 2014 Moderators Solution Share Posted November 11, 2014 (edited) 4b0082,Although the values appear numeric, they may well be stored as strings within the array depending on how you filled it. Use VarGetType to check - and force them to number format with Number if necessary. M23 Edited November 11, 2014 by Melba23 Fixed BB tags 4b0082 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
4b0082 Posted November 11, 2014 Author Share Posted November 11, 2014 (edited) Oh, apparently they were being processed as strings. Would changing this line be enough to have them processed numerically every time? Edit: Seems like it's working so far, just have to let it run for a while to be completely sure! Thanks guys! If Number($Items[$b][1]) < Number($tArray[$a][1]) Then Edited November 11, 2014 by 4b0082 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 11, 2014 Moderators Share Posted November 11, 2014 4b0082,That will do the trick. It is a common problem and as soon as you find comparisons which do not appear to work correctly it should always be your first suspicion. Why does it happen? Because AutoIt variables are not typed and occasionally do not store values in the form you expect - for example anything read from an ini file is automatically stored as a string. Should it happen? Jon made a design decision all those years ago not to use typed variables for ease of use - too late to go back now and so the user has to take care in certain situations, with comparisons being the most frequent problem area. M23 4b0082 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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