Jump to content

Adding column 0 values from an array to a GUI list in order?


Hyflex
 Share

Recommended Posts

Hi,

I'm currently using:

GUICtrlSetData($LeftOutputList, _ArrayToString($PossibleValues))

However, it's inputting them in a random order rather than going in row order or using column 2 as an index (lowest number to highest or vice versa)

How can I make it so it adds them all to the list in the correct order (the order of the array)

Link to comment
Share on other sites

  • Moderators

Hyflex,

List controls are automatically created with the $LBS_SORT style - my bet it is this which is causing the problem. So you need to create the control without this style - the Setting Styles tutorial in the Wiki shows how to go about this.

Come back if you still have problems.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

Hyflex,

Post the code and the data.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

Hi Melba,

Here it is so far:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ListviewConstants.au3>

Local $InputListItems[3] = ["item1", "item2", "item3"]
Local $LeftOptions[] = [""]
Local $RightOptions[] = [""]

$Form1 = GUICreate("Form1", 751, 300, 192, 124)

$InputMain = GUICtrlCreateGroup("Input Main", 8, 0, 137, 137)
$InputListMain = GUICtrlCreateList("", 16, 16, 121, 118)
GUICtrlSetData($InputListMain, _ArrayToString($InputListItems))

$InputAlt = GUICtrlCreateGroup("Input Alt", 151, 0, 137, 137)
$InputListAlt = GUICtrlCreateList("", 159, 16, 121, 118)
GUICtrlSetData($InputListAlt, _ArrayToString($InputListItems))

$Rates = GUICtrlCreateGroup("Rates", 6, 139, 281, 49)
$MainRateInput = GUICtrlCreateInput("1", 14, 155, 121, 21)
$AltRateInput = GUICtrlCreateInput("20", 158, 155, 121, 21)

$LeftOutputs = GUICtrlCreateGroup("Left Option", 296, 0, 209, 235)
$LeftOutputList = GUICtrlCreateList("", 304, 16, 193, 222)
GUICtrlSetData($LeftOutputList, _ArrayToString($LeftOptions))

$RightOutputs = GUICtrlCreateGroup("Right Option", 532, 0, 209, 235)
$RightOutputList = GUICtrlCreateList("", 540, 16, 193, 222)
GUICtrlSetData($RightOutputList, _ArrayToString($RightOptions))

$Output = GUICtrlCreateGroup("Main Output", 8, 242, 281, 49)
$OututInput = GUICtrlCreateInput("", 16, 258, 265, 21)

$Picker = GUICtrlCreateGroup("Option", 294, 242, 345, 49)
$Radio1 = GUICtrlCreateRadio("Left", 312, 266, 113, 17)
$Radio2 = GUICtrlCreateRadio("Right", 488, 266, 113, 17)

GUISetState(@SW_SHOW)
GUICtrlSetState($Radio1, $GUI_CHECKED)
ControlClick("", "", "[CLASS:ListBox; INSTANCE:1]", "left", 1, 20, 20)
ControlClick("", "", "[CLASS:ListBox; INSTANCE:2]", "left", 1, 20, 10)

; Generate on startup
GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput), "left", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput), "right", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))

Func GenerateRates($MainRate, $AltRate, $Position, $item1, $item2)

    ; Set Defaults
    Local $Start = $MainRate
    Local $End = $AltRate
    Local $Pos = $Position

    ; Setup blank array
    Local $PossibleValues[1][] = [["", ""]]
    _ArrayDelete($PossibleValues, 0)

    Local $FloatTrigger = False
    Local $IgnoreTrigger = False

    ; Output item
    If $Pos = "left" Then
        $item = $item1
    Else
        $item = $item2
    EndIf

    ; Clear the output to allow for a fresh list.
    If $Pos = "left" Then
        GUICtrlSetData($LeftOutputList, "")
    Else
        GUICtrlSetData($RightOutputList, "")
    EndIf

    ; Setup initial value
    $PossibleValue = $Start & "/" & $End & " " & $item &" (" & Round($Start / $End, 4) & ")"
    $sFill = $PossibleValue & "|" & Round($Start / $End, 4)
    _ArrayAdd($PossibleValues, $sFill)

    ; Add 15 more values
    For $i = 1 To 15
        $IgnoreTrigger = False

        ; Initial values + a minor increase
        $Start = $Start
        $End = Round($End + 0.1, 1)

        ; Check to see if the end number is an interger or not
        If IsInt(Number($End)) Then
            ;ConsoleWrite("End: " & $End & @CRLF)
            $FloatTrigger = False
        Else
            $FloatTrigger = True
            $StartEx = $Start
            $EndEx = $End
            ;ConsoleWrite("EndEx: " & $EndEx & @CRLF)
        EndIf

        ; While the end number is an interger keep increasing
        While $FloatTrigger = True
            $StartEx = $StartEx + $MainRate
            $EndEx = $EndEx + $AltRate + 0.1
            If IsInt(Number($EndEx)) Then
                $FloatTrigger = False
                ;ConsoleWrite("Int Detected: " & $EndEx & @CRLF)
            Else
                $FloatTrigger = True
            EndIf
            ; If either number gets to 1000+ ignore it and get another loop to make sure we get 15 items but none with rates that are too high.
            If Number($EndEx) >= 1000 or Number($StartEx) >= 1000 Then
                $FloatTrigger = False
                $IgnoreTrigger = True
                $i = $i - 1
            EndIf
        WEnd

        ; Do not add the 1000+ numbers
        If $IgnoreTrigger = False Then
            If IsInt(Number($End)) Then
                $FloatTrigger = False
            Else
                $FloatTrigger = True
            EndIf

            ; Setup other value strings
            If $FloatTrigger = True Then
                $PossibleValue = $StartEx & "/" & $EndEx & " " & $item &" (" & Round($StartEx / $EndEx, 4) & ")"
            Else
                $PossibleValue = $Start & "/" & $End & " " & $item &" (" & Round($Start / $End, 4) & ")"
            EndIf

            ; Add the values to the array
            $sFill = $PossibleValue & "|" & Round($Start / $End, 4)
            _ArrayAdd($PossibleValues, $sFill)

        EndIf
    Next
    ; Display the array for debugging
    _ArrayDisplay($PossibleValues, "")

    ; Update the lists
    If $Pos = "left" Then
        GUICtrlSetData($LeftOutputList, _ArrayToString($PossibleValues))
    Else
        GUICtrlSetData($RightOutputList, _ArrayToString($PossibleValues))
    EndIf

    ;Return $PossibleValues
EndFunc   ;==>GenerateRates

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Radio1
            If GUICtrlRead($OututInput) <> GUICtrlRead($LeftOutputList) Then
                GUICtrlSetData($OututInput, GUICtrlRead($LeftOutputList))
            EndIf
        Case $Radio2
            If GUICtrlRead($OututInput) <> GUICtrlRead($RightOutputList) Then
                GUICtrlSetData($OututInput, GUICtrlRead($RightOutputList))
            EndIf
        ; Working Start
        Case $InputListMain
            GUICtrlSetData($Radio1, "Left: " & GUICtrlRead($InputListMain))
        Case $InputListAlt
            GUICtrlSetData($Radio2, "Right: " & GUICtrlRead($InputListAlt))
        ; Working End
        Case $MainRateInput
            If GUICtrlRead($Radio1) = 1 Then
                GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput), "left", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            Else
                GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput), "right", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            EndIf
        Case $AltRateInput
            If GUICtrlRead($Radio1) = 1 Then
                GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput), "left", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            Else
                GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput), "right", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            EndIf
    EndSwitch
WEnd


You can see I even added a second column to the array to try and get it to sort automatically. The only problem with the second column is I can't seem to get _ArrayToString to only put in column 0 into the list.

As for the lists, if I change:

$LeftOutputList = GUICtrlCreateList("", 304, 16, 193, 222)

to:

$LeftOutputList = GUICtrlCreateList("", 304, 16, 193, 222, $LVS_SORTASCENDING)

Yesterday the lists were coming out with chinese letters in them, today it's not coming out with anything in them. Not sure what is different.

Any advice on what I'm doing wrong?

Link to comment
Share on other sites

  • Moderators

Hyflex,

if you do as I suggested (remove the $LBS_SORT style form the list controls) the lists fill in the order you create the items:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ListviewConstants.au3>

Local $InputListItems[3] = ["item1", "item2", "item3"]
Local $LeftOptions[] = [""]
Local $RightOptions[] = [""]

$Form1 = GUICreate("Form1", 751, 300, 192, 124)

$InputMain = GUICtrlCreateGroup("Input Main", 8, 0, 137, 137)
$InputListMain = GUICtrlCreateList("", 16, 16, 121, 118, BitOr($WS_BORDER, $WS_VSCROLL)) ; Need to set these styles, but not the default $LBS_SORT
GUICtrlSetData($InputListMain, _ArrayToString($InputListItems))

$InputAlt = GUICtrlCreateGroup("Input Alt", 151, 0, 137, 137)
$InputListAlt = GUICtrlCreateList("", 159, 16, 121, 118, BitOr($WS_BORDER, $WS_VSCROLL)) ; As above
GUICtrlSetData($InputListAlt, _ArrayToString($InputListItems))

$Rates = GUICtrlCreateGroup("Rates", 6, 139, 281, 49)
$MainRateInput = GUICtrlCreateInput("1", 14, 155, 121, 21)
$AltRateInput = GUICtrlCreateInput("20", 158, 155, 121, 21)

$LeftOutputs = GUICtrlCreateGroup("Left Option", 296, 0, 209, 235)
$LeftOutputList = GUICtrlCreateList("", 304, 16, 193, 222, BitOr($WS_BORDER, $WS_VSCROLL)) ; As above
GUICtrlSetData($LeftOutputList, _ArrayToString($LeftOptions))

$RightOutputs = GUICtrlCreateGroup("Right Option", 532, 0, 209, 235)
$RightOutputList = GUICtrlCreateList("", 540, 16, 193, 222, BitOr($WS_BORDER, $WS_VSCROLL)) ; As above
GUICtrlSetData($RightOutputList, _ArrayToString($RightOptions))

$Output = GUICtrlCreateGroup("Main Output", 8, 242, 281, 49)
$OututInput = GUICtrlCreateInput("", 16, 258, 265, 21)

$Picker = GUICtrlCreateGroup("Option", 294, 242, 345, 49)
$Radio1 = GUICtrlCreateRadio("Left", 312, 266, 113, 17)
$Radio2 = GUICtrlCreateRadio("Right", 488, 266, 113, 17)

GUISetState(@SW_SHOW)
GUICtrlSetState($Radio1, $GUI_CHECKED)
ControlClick("", "", "[CLASS:ListBox; INSTANCE:1]", "left", 1, 20, 20)
ControlClick("", "", "[CLASS:ListBox; INSTANCE:2]", "left", 1, 20, 10)

; Generate on startup
GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput), "left", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput), "right", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Radio1
            If GUICtrlRead($OututInput) <> GUICtrlRead($LeftOutputList) Then
                GUICtrlSetData($OututInput, GUICtrlRead($LeftOutputList))
            EndIf
        Case $Radio2
            If GUICtrlRead($OututInput) <> GUICtrlRead($RightOutputList) Then
                GUICtrlSetData($OututInput, GUICtrlRead($RightOutputList))
            EndIf
        ; Working Start
        Case $InputListMain
            GUICtrlSetData($Radio1, "Left: " & GUICtrlRead($InputListMain))
        Case $InputListAlt
            GUICtrlSetData($Radio2, "Right: " & GUICtrlRead($InputListAlt))
        ; Working End
        Case $MainRateInput
            If GUICtrlRead($Radio1) = 1 Then
                GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput), "left", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            Else
                GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput), "right", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            EndIf
        Case $AltRateInput
            If GUICtrlRead($Radio1) = 1 Then
                GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput), "left", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            Else
                GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput), "right", GUICtrlRead($InputListMain), GUICtrlRead($InputListAlt))
            EndIf
    EndSwitch
WEnd

Func GenerateRates($MainRate, $AltRate, $Position, $item1, $item2)

    ; Set Defaults
    Local $Start = $MainRate
    Local $End = $AltRate
    Local $Pos = $Position

    ; Setup blank array
    Local $PossibleValues[0] ; This is how you create an empty array
    ;_ArrayDelete($PossibleValues, 0)

    Local $FloatTrigger = False
    Local $IgnoreTrigger = False

    ; Output item
    If $Pos = "left" Then
        $item = $item1
    Else
        $item = $item2
    EndIf

    ; Clear the output to allow for a fresh list.
    If $Pos = "left" Then
        GUICtrlSetData($LeftOutputList, "")
    Else
        GUICtrlSetData($RightOutputList, "")
    EndIf

    ; Setup initial value
    $PossibleValue = $Start & "/" & $End & " " & $item &" (" & Round($Start / $End, 4) & ")"
    $sFill = $PossibleValue ; & "|" & Round($Start / $End, 4) ; Second section removed
    _ArrayAdd($PossibleValues, $sFill)
    ConsoleWrite($sFill & @CRLF) ; Easier for debugging than an ArrayDisplay

    ; Add more values
    For $i = 1 To 10
        $IgnoreTrigger = False

        ; Initial values + a minor increase
        $Start = $Start
        $End = Round($End + 0.1, 1)

        ; Check to see if the end number is an interger or not
        If IsInt(Number($End)) Then
            ;ConsoleWrite("End: " & $End & @CRLF)
            $FloatTrigger = False
        Else
            $FloatTrigger = True
            $StartEx = $Start
            $EndEx = $End
            ;ConsoleWrite("EndEx: " & $EndEx & @CRLF)
        EndIf

        ; While the end number is an interger keep increasing
        While $FloatTrigger = True
            $StartEx = $StartEx + $MainRate
            $EndEx = $EndEx + $AltRate + 0.1
            If IsInt(Number($EndEx)) Then
                $FloatTrigger = False
                ;ConsoleWrite("Int Detected: " & $EndEx & @CRLF)
            Else
                $FloatTrigger = True
            EndIf
            ; If either number gets to 1000+ ignore it and get another loop to make sure we get 15 items but none with rates that are too high.
            If Number($EndEx) >= 1000 or Number($StartEx) >= 1000 Then
                $FloatTrigger = False
                $IgnoreTrigger = True
                $i = $i - 1
            EndIf
        WEnd

        ; Do not add the 1000+ numbers
        If $IgnoreTrigger = False Then
            If IsInt(Number($End)) Then
                $FloatTrigger = False
            Else
                $FloatTrigger = True
            EndIf

            ; Setup other value strings
            If $FloatTrigger = True Then
                $PossibleValue = $StartEx & "/" & $EndEx & " " & $item &" (" & Round($StartEx / $EndEx, 4) & ")"
            Else
                $PossibleValue = $Start & "/" & $End & " " & $item &" (" & Round($Start / $End, 4) & ")"
            EndIf

            ; Add the values to the array
            $sFill = $PossibleValue ; & "|" & Round($Start / $End, 4) ; See above
            _ArrayAdd($PossibleValues, $sFill)
            ConsoleWrite($sFill & @CRLF) ; See above

        EndIf
    Next
    ; Display the array for debugging
    ;_ArrayDisplay($PossibleValues, "")

    ; Update the lists
    If $Pos = "left" Then
        GUICtrlSetData($LeftOutputList, _ArrayToString($PossibleValues))
    Else
        GUICtrlSetData($RightOutputList, _ArrayToString($PossibleValues))
    EndIf


    ConsoleWrite(@CRLF)

    ;Return $PossibleValues
EndFunc   ;==>GenerateRates

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

@Melba23

I think my maths in my head was a bit wrong because even still that output is incorrect, the division is what it should be sorted by for example, if you run that script you'll see that 6 down is: 1/21 which comes out at 0.0476. Yet if you look at 7 down it shows 5/102 which comes out as 0.049 which is bigger than the previous one, therefore it should be put slightly higher.

I might be going about doing the UI completely wrong, I'll try and explain with a made up scenario of what I am trying to achieve but in a way everyone can understand.

pvaQmrB.png

If we were to buy 20 silver for 1 gold it would be a ratio of 1:20
- I'd want the left options to show 1:20 in its list but also 10 (just an easy to work with number) other options, 5 where the ratio is slightly higher and 5 where the ratio is slightly lower

If we want to make some profit we would have to sell at a ratio lower than 1:20
- So on the right hand side it should show the "same" ratio of 20:1 but it should again also show another 10 options, 5 where the ratio is slightly higher and 5 where it is slightly lower.

It would be ideal if I could somehow click on one on the left options and for it to update the right side and for it to highlight options on the right hand side, blue for the same ratio and then red for a "worse" ratio where we would be making a loss and then green for a good ratio where we would be making profit.

I might be doing it completely wrong but I don't know

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...