gottygolly Posted October 22, 2014 Share Posted October 22, 2014 I got bored so I just started to mess around but for some reason the list box keeps switching up the order. It seems to go 1-9 then when it hits 10 it puts it under 1 and goes until 19 then when it hits 20 it puts it under 2, etc.... I couldn't find/figure this one out so hopefully someone else is able to. Heres the code expandcollapse popup#include <ListBoxConstants.au3> $gui = GUICreate("",300,300,-1,-1) $time = 0 $r = 0 $r2 = 0 $match = 0 $avg = 0 $lab1 = GUICtrlCreateLabel("Number: "&$r,5,5,100,20) $lab2 = GUICtrlCreateLabel("Number: "&$r2,5,25,100,20) $try = GUICtrlCreateLabel("Attempt: "&$time,80,5,100,20) $log = GUICtrlCreateList("",5,105,200,200,$LBS_SORT) $same = GUICtrlCreateLabel("Matches: "&$match,80,30,100,20) $average = GUICtrlCreateLabel("Percentage: "&$avg&"%",150,30,120,20) $check = GUICtrlCreateButton("Start",5,70,100,20) GUISetState() While 1 $msg = GUIGetMsg(1) Switch $msg[1] Case $gui Switch $msg[0] Case -3 Exit Case $check $time = 0 $al = 0 Do $r = Random(0,50,0) $r2 = Random(0,50,0) GUICtrlSetData($lab1,"Number: "&Round($r)) GUICtrlSetData($lab2,"Number: "&Round($r2)) $time = $time + 1 GUICtrlSetData($try,"Attempt: "&$time) If Round($r) = Round($r2) Then ; MsgBox(0,"","Match!") $al = $al + 1 GUICtrlSetData($log,$al&". "&"Attempt: "&$time&", Numbers: "&Round($r)&"--"&Round($r2)) $match = $match + 1 GUICtrlSetData($same,"Matches: "&$match) EndIf $avg = $time / $match GUICtrlSetData($average,"Percentage: "&Round($avg,0)&"%") If $avg >= 100 Then $avg2 = $avg - 100 $avg = $avg - $avg2 GUICtrlSetData($average,"Percentage: "&Round($avg,0)&"%") EndIf Sleep(100) Until $time = 500000 EndSwitch EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 22, 2014 Moderators Share Posted October 22, 2014 gottygolly,You have set the $LBS_SORT style for the ListBox - just specify the other default styles instead: $log = GUICtrlCreateList("", 5, 105, 200, 200, BitOr($WS_BORDER, $WS_VSCROLL))The Setting Styles tutorial in the Wiki explains what is going on in more detail. M23 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...
kylomas Posted October 22, 2014 Share Posted October 22, 2014 gottagolly, Additional comments for your consideration: Return an integer from your random function to avoid having to use the Round function for $r and $r2 (3RD parm of Random - see Help file). Use StringFormat to zero fill numbers to whatever length you want. This keeps them in sort order if you want to keep the sort style. Don't use a sleep in the message loop. GuiGetMsg idles the loop for you. The advanced form of GuiGetMsg ( GuiGetMsg(1) ) is unnecessary unless you have multiple gui's, need the actioned controls handle or want to get the mouse cursor position when a control is actioned. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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