Jump to content

dynamic buttons


Recommended Posts

hi guys,

im fairly new to autoit even tho i have known about it for years i never really had a need to use it until now.

its abilities seem pretty sweet and im sure ill find alot more use for it :rolleyes:

now for my problem - i have a combobox with numbers 1 to 48 in it which i use to generate buttons dynamically.

that part works fine, however when i choose less buttons then the previous one (ie 12 buttons to 8 buttons) and do this multiply times

with different values the array seems to get confused and no longer removes the range of buttons.

if i just loop through deleting all buttons everytime regardless this works fine but seems quite inefficient.

Dim $btn[48]
Local $totalBtns = 0

$numberCombo = GUICtrlCreateCombo('', 100, 50, 145, 25)
GUICtrlSetData($numberCombo, totalNumbers()) 
GUICtrlSetOnEvent($numberCombo, 'numberComboChange')

Func totalNumbers()
    Local $items
    For $i = 1 to 48 Step 1
        $items &= $i & '|'
    Next
    return $items
EndFunc

Func numberComboChange()
    $result = GUICtrlRead($numberCombo)
    ;If $totalBtns > 0 Then
    ;   MsgBox(4096, '', 'start deleting')
    ;   For $i = 1 To $totalBtns
    ;       GUICtrlDelete($btn[$i])
    ;   Next
    ;EndIf
    If $result < $totalBtns Then
        MsgBox(4096, '', 'start deleting')
        MsgBox(4096, '', 'result ' & $result & ' totalBtns ' & $totalBtns)
        For $i = $totalBtns To $result Step - 1
            GUICtrlDelete($btn[$i])
        Next
    EndIf
    genrateButtons($result)
EndFunc

Func genrateButtons($btns)
    $x = 20
    $y = 100
    For $i = 1 To $btns
        $btn[$i] = GUICtrlCreateButton('Button ' & $i, $x, $y, 60, 25, 0)
        GUICtrlSetOnEvent(-1, 'copyNumber')
        $x += 65
        If mod($i, 6) = 0 Then
            $x = 20
            $y += 30
        EndIf
        $totalBtns = $i
    Next
EndFunc

any help would be greatly appreciated.

thanks

Link to comment
Share on other sites

Should not this take into account the existing buttons?

Func genrateButtons($btns)
    $x = 20
    $y = 100
    For $i = 1 To $btnsoÝ÷ Ù*+^®Ê&zØb  b殶­sdgVæ2vVç&FT'WGFöç2b33c¶'2¢b33c·Ò#¢b33c·Ò¢f÷"b33c¶Òb33c¶Æ7D'FâFòb33c¶'Fç0

You could save the last valide button at $btn[0] to keep track if it.

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