Jump to content

What to make the interface more user-friendly.


ASut
 Share

Recommended Posts

Please rank your preference or the hair product brands listed below by ranking them 1-5.

口 Tigi

口 Wella

口 Loreal

口 Schwarzkopf

口 Pantene

Hi, How can I make this interface in Autoit more user-friendly to collect some data? And save the result in the *.txt file.

Thanks in advance.

Link to comment
Share on other sites

  • Moderators

Asut,

Perhaps like this? :graduated:

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

Global $aCombo[5], $aResult[5], $aTitle[5] = ["Tigi", "Wella", "Loreal", "Schwarzkopf", "Pantene"]

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Please rank your preference or the hair product brands listed below by ranking them 1-5:", 10, 10, 480, 20)

For $i = 0 To 4
    $aCombo[$i] = GUICtrlCreateCombo("", 10, 50 + (25 * $i), 35, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "1|2|3|4|5")
    GUICtrlCreateLabel($aTitle[$i], 50, 50 + (25 * $i), 100, 20)
Next

$hButton = GUICtrlCreateButton("Save", 10, 200, 80, 30)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCombo[0] To $aCombo[4]
            ; Read selection
            $iSelection = GUICtrlRead($iMsg) - 1
            $iIndex = $aResult[$iSelection]
            If $iIndex <> $iMsg Then
                ; Reset any existing selection
                GUICtrlSetData($iIndex, "|1|2|3|4|5")
                For $i = 0 To 4
                    If $aResult[$i] = $iMsg Then
                        $aResult[$i] = ""
                    EndIf
                Next
                ; And set new one
                $aResult[$iSelection] = $iMsg
            EndIf
        Case $hButton
            $fError = False
            ; Check all combos set
            For $i = 0 To 4
                If GUICtrlRead($aCombo[$i]) = "" Then
                    MsgBox(0, "Oops!", "Please set all the values")
                    $fError = True
                    ExitLoop
                EndIf
            Next
            If Not $fError Then
                ; Write the file
                $hFile = FileOpen(@ScriptDir & "\Results.txt", 2)
                For $i = 0 To 4
                    FileWriteLine($hFile, GUICtrlRead($aCombo[$i]) & " - " & $aTitle[$i])
                Next
                FileClose($hFile)
            EndIf
    EndSwitch

WEnd

You cannot double select a value and all combos must be set before you can write the file.

I hope it helps. ;)

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

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
    GUICreate("TEST", 400, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    $listview = GUICtrlCreateListView("ID|Tigi|Wella|Loreal|Schwarzkopf|Pantene", 10, 10, 380, 100)
    $item1 = GUICtrlCreateListViewItem("1|1|2|3|4|5", $listview)
    $item2 = GUICtrlCreateListViewItem("2|5|4|3|2|1", $listview)
    $item3 = GUICtrlCreateListViewItem("3|2|1|5|4|3", $listview)
 
$list1=GUICtrlCreateListView("ID|1|2|3|4|5", 10, 130, 380, 100)
    $item1 = GUICtrlCreateListViewItem("1|Tigi|Wella|Loreal|Schwarzkopf|Pantene", $list1)
    $item2 = GUICtrlCreateListViewItem("2|Schwarzkopf|Tigi|Wella|Loreal|Pantene", $list1)
    $item3 = GUICtrlCreateListViewItem("3|Tigi|Wella|Loreal|Schwarzkopf|Pantene", $list1)
    GUISetState()
 
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
Thanks for the help, how can I write the other interface to read the data stored in the *.txt file?

Something like that but allow the admin to change the order.

Link to comment
Share on other sites

  • Moderators

ASut,

Use this slightly changed script to create the Results.txt file: :graduated:

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

Global $aCombo[5], $aResult[5], $aTitle[5] = ["Tigi", "Wella", "Loreal", "Schwarzkopf", "Pantene"]

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Please rank your preference or the hair product brands listed below by ranking them 1-5:", 10, 10, 480, 20)

For $i = 0 To 4
    $aCombo[$i] = GUICtrlCreateCombo("", 10, 50 + (25 * $i), 35, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "1|2|3|4|5")
    GUICtrlCreateLabel($aTitle[$i], 50, 50 + (25 * $i), 100, 20)
Next

$hButton = GUICtrlCreateButton("Save", 10, 200, 80, 30)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCombo[0] To $aCombo[4]
            ; Read selection
            $iSelection = GUICtrlRead($iMsg) - 1
            $iIndex = $aResult[$iSelection]
            If $iIndex <> $iMsg Then
                ; Reset any existing selection
                GUICtrlSetData($iIndex, "|1|2|3|4|5")
                For $i = 0 To 4
                    If $aResult[$i] = $iMsg Then
                        $aResult[$i] = ""
                    EndIf
                Next
                ; And set new one
                $aResult[$iSelection] = $iMsg
            EndIf
        Case $hButton
            $fError = False
            ; Check all combos set
            For $i = 0 To 4
                If GUICtrlRead($aCombo[$i]) = "" Then
                    MsgBox(0, "Oops!", "Please set all the values")
                    $fError = True
                    ExitLoop
                EndIf
            Next
            If Not $fError Then
                ; Write the return to the file
                $hFile = FileOpen(@ScriptDir & "\Results.txt", 1)
                FileWriteLine($hFile, "## Result ##")
                For $i = 0 To 4
                    FileWriteLine($hFile, GUICtrlRead($aCombo[$i]) & " - " & $aTitle[$i])
                Next
                FileClose($hFile)
            EndIf
    EndSwitch

WEnd

And then this one will parse the file and fill the ListViews: ;)

#include <GUIConstantsEx.au3>
#include <File.au3>
#Include <GuiListView.au3>
#include <Array.au3>

; Read in file
Global $aLines
_FileReadToArray(@ScriptDir & "\Results.txt", $aLines)

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$hLV_1 = GUICtrlCreateListView("ID|Loreal|Pantene|Schwarzkopf|Tigi|Wella", 10, 10, 480, 100) ; Need names in alphabetical order
_GUICtrlListView_SetColumnWidth($hLV_1, 5, 15)
For $i = 1 To 4
    _GUICtrlListView_SetColumnWidth($hLV_1, $i, 90)
Next
_GUICtrlListView_SetColumnWidth($hLV_1, 5, $LVSCW_AUTOSIZE_USEHEADER)

$hLV_2 = GUICtrlCreateListView("ID|1|2|3|4|5", 10, 150, 480, 100)
_GUICtrlListView_SetColumnWidth($hLV_2, 5, 15)
For $i = 1 To 4
    _GUICtrlListView_SetColumnWidth($hLV_2, $i, 90)
Next
_GUICtrlListView_SetColumnWidth($hLV_2, 5, $LVSCW_AUTOSIZE_USEHEADER)

; Parse file
$iStart_Line = 2
$iIndex = 1
While $iStart_Line < $aLines[0]

    ; Create array to hold results from this return
    Global $aResult[5][2]
    ; Fill array
    For $i = 0 To 4
        $aSplit = StringSplit($aLines[$iStart_Line + $i], " - ", 1)
        $aResult[$i][0] = $aSplit[1]
        $aResult[$i][1] = $aSplit[2]
    Next
    ; Sort array into numerical order of selection and create row variable for LV_2
    _ArraySort($aResult)
    $sLVItem_2 = $iIndex
    For $i = 0 To 4
        $sLVItem_2 &= "|" & $aResult[$i][1]
    Next
    GUICtrlCreateListViewItem($sLVItem_2, $hLV_2)

    ; Now sort array into alphabetical order of product and create row variable for LV_1
    _ArraySort($aResult, 0, 0, 0, 1)
    $sLVItem_1 = $iIndex
    For $i = 0 To 4
        $sLVItem_1 &= "|" & $aResult[$i][0]
    Next
    GUICtrlCreateListViewItem($sLVItem_1, $hLV_1)

    ; Set file values for next return
    $iIndex += 1
    $iStart_Line += 6
WEnd

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Enough from me - your turn to do some coding. :)

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

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...