I have a thousands mini tools, I am trying to create a menu by using Autuit. I have to define thousand functions and case and variable how i can make it easy. here is my code how can use loop for select case and run soft.exe
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("MainMenu", 615, 437, 192, 124)
$Soft1 = GUICtrlCreateButton("Button1", -8, 0, 75, 25)
$Soft2 = GUICtrlCreateButton("Button2", -18, 10, 75, 25)
$Soft3 = GUICtrlCreateButton("Button3", -28, 20, 75, 25)
$Soft4 = GUICtrlCreateButton("Button4", -38, 30, 75, 25)
$Soft5 = GUICtrlCreateButton("Button5", -48, 40, 75, 25)
$Soft6 = GUICtrlCreateButton("Button6", -58, 50, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Soft1
Startsoft1()
Case $Soft2
Startsoft2()
Case $Soft3
Startsoft3()
Case $Soft4
Startsoft4()
Case $Soft5
Startsoft5()
Case $Soft6
Startsoft6()
EndSwitch
WEnd
Func Startsoft1()
Run('Soft1.exe')
EndFunc
Func Startsoft2()
Run('Soft2.exe')
EndFunc
Func Startsoft3()
Run('Soft3.exe')
EndFunc
Func Startsoft4()
Run('Soft4.exe')
EndFunc
Func Startsoft5()
Run('Soft5.exe')
EndFunc
iam new in programing there for learning new things
Try something like this as a good starting point. Put the names and pathes in the strings of the method StringSplit. The GUI buttons are automatically placed in a new line if the button reaches the GUI width end.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
main()
Func main()
Local $gui_width = @DesktopWidth -100, $gui_height = @DesktopHeight - 80
Local $Form1 = GUICreate("MainMenu", $gui_width, $gui_height, 50, 10)
Local $exesName_A = StringSplit('a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe', ',', 2)
Local $exesPath_A = StringSplit('a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe', ',', 2)
Local $height = 45, $width = 125, $y = 0, $x = 0
Local $button_A[UBound($exesName_A)]
For $i = 0 To UBound($exesName_A) - 1
If ((8 + ($x + 1) * $width) > $gui_width) Then
$y += 1
$x = 0
EndIf
$button_A[$i] = GUICtrlCreateButton($exesName_A[$i], 8 + $x * $width, 10 + $y * $height, 75, $height)
GUICtrlSetImage(-1, "shell32.dll", 22+ $i)
$x += 1
Next
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
; scan all buttons to check if one was pressed
For $i = 0 To UBound($button_A) - 1
If $nMsg = $button_A[$i] Then
ConsoleWrite('Now run the exe' & $exesPath_A[$i] & @CRLF)
;~ ShellExecute($exesPath_A[$i], '') ; uncomment this to run the exe
EndIf
Next
WEnd
EndFunc ;==>main