Hyflex Posted June 11, 2015 Posted June 11, 2015 Hi,I have an INI file that consists of:[test] varold1=test1 varnew1=test2 varroll1=test3 varpast1=test4 varnext1=test5 varold2=word1 varnew2=word2 varroll2=word3 varpast2=word4 varnext2=word5 varold2=name1 varnew2=name2 varroll2=name3 varpast2=name4 varnext2=name5If you use the following code, it will give you a number of buttons I need (in this case it would return 3)$aSettings = IniReadSection("Settings.ini", "test") $vNumber = $aSettings[0][0] / 5I then want a simple GUI with 3 buttons (could be 1 button, 2 buttons, 20 buttons but the max I will ever have is 30)The names of the buttons would be one of the accompanying variablesIniRead($settingsfilelocation, "test", "varpast" & $i, "")Clicking the first button would send the function doThis($i) and the $i variable would just be the number of what button was pressed in this case it would be 1, so then I can easily see what variables are associated with 1 in the ini file, using the same iniread from above.How would I achieve a GUI like this?
Moderators Melba23 Posted June 11, 2015 Moderators Posted June 11, 2015 Hyflex,You will need to develop an algorithm along these lines (I used the data you provided above):expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $iMax_Across = 3 ; Max buttons per row $iButton_Height = 30 ; Size of button $iButton_Width = 80 ; $iBorder = 10 ; Size of border around buttons ; Read ini and get number of buttons $aSettings = IniReadSection("Settings.ini", "test") $vNumber = $aSettings[0][0] / 5 ; Create array to hold button ControlIDs Global $aButton[$vNumber] ; Determine number of rows required $iRows = Int($vNumber / $iMax_Across) ; Set GUI width If $iRows Then $iGui_Width = ($iButton_Width * $iMax_Across) + ($iBorder * ( $iMax_Across + 1)) Else $iGui_Width = ($iButton_Width * $vNumber) + ($iBorder * ($vNumber + 1)) EndIf ; Set GUI height $iGUI_Height = ($iButton_Height * ($iRows + 1)) + ($iBorder * ($iRows + 2)) ; Create GUI $hGUI = GUICreate("Test", $iGui_Width, $iGUI_Height) ; Create buttons For $i = 0 To $iRows ; Determine Y-coord for this row $iY = ($iButton_Height * $i) + ($iBorder * ($i + 1)) For $j = 0 To $iMax_Across - 1 ; Determine X-coord for this button $iX = ($iButton_Width * $j) + ($iBorder * ($j + 1)) ; Determine index for this button $iIndex = $j + ($i * $iMax_Across) ; Create buttona nd add ControlID to array $aButton[$iIndex] = GUICtrlCreateButton($iIndex + 1, $iX, $iY, $iButton_Width, $iButton_Height) ; If last button created then stop If $iIndex = $vNumber - 1 Then ExitLoop 2 Next Next GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case Else ; See if button actioned For $i = 0 To $vNumber - 1 If $iMsg = $aButton[$i] Then ; Retrieve data depending on button index MsgBox($MB_SYSTEMMODAL, "Retrieved", IniRead("Settings.ini", "test", "varpast" & $i + 1, "")) ; No point in looking further ExitLoop EndIf Next EndSwitch WEndPlease ask if you have any questions.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
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