Jump to content

Recommended Posts

Posted

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=name5


If 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] / 5


I 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 variables

IniRead($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
Posted

Hyflex,

You will need to develop an algorithm along these lines (I used the data you provided above):

#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



WEnd

Please ask if you have any questions.

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

 

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
×
×
  • Create New...