Sign in to follow this  
Followers 0
gottygolly

List box mixing up.

3 posts in this topic

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

#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

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0