Zithen Posted July 27, 2014 Posted July 27, 2014 Its been a very long time since I have used Autoit and just kind of getting back into it. Was creating a basic script that would load the contents of a ini file and create a button next to them where you click on the button and it would delete that corresponding ini entry. Couldn't get it working so now just trying to get it to where you click the button it will display a msgbox with the value. figure getting that to work will make the next step easier. However I have kind of gotten lost and the msgbox just appears repeatedly. Had it at one point where it didn't, but the msgboxs never worked or just didn't display any data. After a few edits and trying to follow _GUICtrlButton_click help, I have gotten so lost and not sure where to go with it heh. expandcollapse popup#include <ButtonConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=button.kxf $Form1_1 = GUICreate("Form1", 414, 426, 192, 124) $MenuItem1 = GUICtrlCreateMenu("&File") $MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1) $Group1 = GUICtrlCreateGroup("Group", 24, 8, 361, 337, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER)) GUICtrlSetFont(-1, 30, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $reloadList = GUICtrlCreateButton("Reload List", 128, 360, 99, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $button[20], $aArray, $player reloadIni() Func reloadIni() Local $buttonY = 40 ; Read the INI section labelled 'General'. This will return a 2 dimensional array. Local $aArray = IniReadSection("random.ini", "Things") ; Check if an error occurred. If Not @error Then ; Enumerate through the array displaying the keys and their respective values. For $i = 1 To $aArray[0][0] GUISetFont(16, 700, 4, "Times New Roman") $button[$i] = GUICtrlCreateButton("X", 30, $buttonY+5, 15, 20) GUICtrlCreateLabel($aArray[$i][0], 50, $buttonY, 240, 40) GUICtrlCreateLabel($aArray[$i][1], 250, $buttonY, 40, 40) $buttonY += 30 Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $reloadList reloadIni() Case $button[$i] buttonid($button[$i]) ;MsgBox($MB_SYSTEMMODAL, "", $button[$i]) EndSwitch WEnd EndFunc Func buttonid($id) MsgBox($MB_SYSTEMMODAL, "", $id) EndFunc
Zithen Posted July 30, 2014 Author Posted July 30, 2014 not sure if i explained well enough of what i was trying to do, so thought i would do it a little simpler. using a for loop through a array to generate buttons. When you click on the button it bring up a message box with the value of its corresponding array value (click button 5 it would display 5). Have tried a few different ways and can't seem to get a solution. latest code snip i have tried. Global $testingbuttons[10], $starty = 70, $i for $i=0 To UBound($testingbuttons)-1 $testingbuttons[$i] = GUICtrlCreateButton("Button "& $i, -1, $starty, 100, 30) $starty += 35 Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $testingbuttons MsgBox($MB_SYSTEMMODAL, "work?", $testingbuttons[$i]) EndSwitch WEnd
Moderators Melba23 Posted July 30, 2014 Moderators Posted July 30, 2014 Zithen,This should give some idea of how you might go about it: expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; Create an array to hold the button data and the control Ids Global $aButtons[5][2] ; Add the data For $i = 0 To 4 $aButtons[$i][0] = "Button " & $i & " pressed" Next $hGUI = GUICreate("Test", 500, 500) ; Create the buttons and add their ControlIDs to the array For $i = 0 To UBound($aButtons) - 1 $aButtons[$i][1] = GUICtrlCreateButton("Button " & $i, 10, 10 + (40 * $i), 80, 30) Next GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit ; Was the ControlID a button? Case Else For $i = 0 To UBound($aButtons) - 1 If $iMsg = $aButtons[$i][1] Then ; If so then display the data MsgBox($MB_SYSTEMMODAL, "Button Pressed", $aButtons[$i][0]) ; 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
Solution Zithen Posted July 31, 2014 Author Solution Posted July 31, 2014 Thanks so much. Never thought to use a multi dimensional array for this.
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