ASut Posted September 24, 2011 Share Posted September 24, 2011 Please rank your preference or the hair product brands listed below by ranking them 1-5.口 Tigi口 Wella口 Loreal口 Schwarzkopf口 PanteneHi, 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 More sharing options...
Moderators Melba23 Posted September 24, 2011 Moderators Share Posted September 24, 2011 Asut, Perhaps like this? expandcollapse popup#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 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...
ASut Posted September 24, 2011 Author Share Posted September 24, 2011 #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 WEndThanks 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 More sharing options...
Moderators Melba23 Posted September 24, 2011 Moderators Share Posted September 24, 2011 ASut,Use this slightly changed script to create the Results.txt file: expandcollapse popup#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 WEndAnd then this one will parse the file and fill the ListViews: expandcollapse popup#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 WEndEnough from me - your turn to do some coding. 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...
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