Wader Posted August 6, 2008 Share Posted August 6, 2008 I am working on a project that will dyanmically create buttons. That process is working now thanks to help from this board. My issue now is that I don't want to create Case statement for all possible buttons created like in the below example. Is there a way to get around this? expandcollapse popup#include <array.au3> Dim $GUI_DOCKHEIGHT, $GUI_DOCKWIDTH, $GUI_EVENT_CLOSE, $Label1, $Label2, $Manual, $GUI Dim $Application1, $Application2, $Application3, $Application4, $Application5, $Application6, $Application7, $Application8, $Application9, $Application10 Dim $ManualAutoInstall, $ManualAutoInstall1, $ManualAutoInstall2, $ManualAutoInstall3, $ManualAutoInstall4, $ManualAutoInstall5, $ManualAutoInstall6, $ManualAutoInstall7, $ManualAutoInstall8, $ManualAutoInstall9, $ManualAutoInstall10 Dim $AutoAutoInstall, $AutoAutoInstall1, $AutoAutoInstall2,$AutoAutoInstall3,$AutoAutoInstall4, $AutoAutoInstall5, $AutoAutoInstall6, $AutoAutoInstall7, $AutoAutoInstall8, $AutoAutoInstall9, $AutoAutoInstall10 Dim $AppButtons, $CaseNumber msgbox(0,"Case Number", $CaseNumber) $AppInstall = GUICreate(IniRead("applicationstest.ini","GUIConfig","GuiTitle",""), IniRead("applicationstest.ini","GUIConfig","GuiWidth",""), IniRead("applicationstest.ini","GUIConfig","GuiHeight",""), IniRead("applicationstest.ini","GUIConfig","GUILeft",""), IniRead("applicationstest.ini","GUIConfig","GUITop","")) $Auto = GUICtrlCreateTab(IniRead("applicationstest.ini","GUIConfig","TabLeft",""), IniRead("applicationstest.ini","GUIConfig","TabTop",""), IniRead("applicationstest.ini","GUIConfig","TabWidth",""), IniRead("applicationstest.ini","GUIConfig","TabHeight","")) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) #Region Tab1 - Auto Apps $Auto = GUICtrlCreateTabItem("Auto") $AutoAppList = IniReadSectionNames("applicationstest.ini") Global $avArray[1000][1000] $RadioHeight = 150 For $i = 1 to $AutoAppList[0] $ApplicationName = IniRead("applicationstest.ini",$AutoAppList[$i],"Name","") $ApplicationDistribMode = IniRead("applicationstest.ini",$AutoAppList[$i],"DistributionMode","") $ApplicationInstallScript = IniRead("applicationstest.ini",$AutoAppList[$i],"InstallScript","") $avArray[$i][0] = $AutoAppList[$i] $avArray[$i][1] = $ApplicationInstallScript If $ApplicationDistribMode = "Auto" Then $AutoAppListName = GUICtrlCreateLabel($ApplicationName, 30, $RadioHeight, 140, 17) If $ApplicationDistribMode = "Auto" AND $ApplicationInstallScript <> "" Then $avArray[$i][0] = GUICtrlCreateButton("Auto Install", 245, $RadioHeight, 75, 17) If $ApplicationDistribMode = "Auto" Then $RadioHeight = $RadioHeight + 20 Next $AutoQUITTop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $AutoUPDATETop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $AutoUpdateINI = GUICtrlCreateButton("UPDATE", 375, $AutoUPDATETop, 100, 25) $AutoQuit = GUICtrlCreateButton("QUIT", 485, $AutoQUITTop, 100, 25) #EndRegion #Region Tab2 - Manual Apps $Manual = GUICtrlCreateTabItem("Manual") $ManualAppList = IniReadSectionNames("applicationstest.ini") $RadioHeight = 150 For $j = 2 to $ManualAppList[0] $AppID = $j $ApplicationName = IniRead("applicationstest.ini",$ManualAppList[$j],"Name","") $ApplicationDistribMode = IniRead("applicationstest.ini",$ManualAppList[$j],"DistributionMode","") $ApplicationInstallScript = IniRead("applicationstest.ini",$ManualAppList[$j],"InstallScript","") $avArray[$i][0] = $ManualAppList[$j] $avArray[$i][1] = $ApplicationInstallScript If $ApplicationDistribMode = "Manual" Then $ManualAppList[$j] = GUICtrlCreateLabel($ApplicationName, 30, $RadioHeight, 140, 17) If $ApplicationDistribMode = "Manual" AND $ApplicationInstallScript <> "" Then $avArray[$j][0] = GUICtrlCreateButton("AutoInstall", 245, $RadioHeight, 75, 17) If $ApplicationDistribMode = "Manual" Then $RadioHeight = $RadioHeight + 20 $ManualAutoInstall = $ManualAutoInstall & $AppID Next $ManualQUITTop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $ManualUPDATETop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $ManualUpdateINI = GUICtrlCreateButton("UPDATE", 375, $ManualUPDATETop, 100, 25) $ManualQuit = GUICtrlCreateButton("QUIT", 485, $ManualQUITTop, 100, 25) #EndRegion GUICtrlCreateTabItem("") $Header = GUICtrlCreateLabel(IniRead("applicationstest.ini","GUIConfig","Title",""), IniRead("applicationstest.ini","GUIConfig","TitleLeft",""), IniRead("applicationstest.ini","GUIConfig","TitleDown",""), IniRead("applicationstest.ini","GUIConfig","TitleWidth",""), IniRead("applicationstest.ini","GUIConfig","TitleHeight","")) GUICtrlSetFont(-1, 20, 800, 0, "Arial Black") $Intro = GUICtrlCreateLabel(IniRead("applicationstest.ini","GUIConfig","Info",""), 20, 56, 600, 55) GUISetState(@SW_SHOW) While $GUI <> "QUIT" $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Case $AutoQuit Exit Case $ManualQuit Exit Case $AutoUpdateINI msgbox(4096,"Hold on!", "Not done yet") Case $ManualUpdateINI msgbox(4096,"Hold on!", "Not done yet") Case $avArray[1][0] $CaseNumber = "1" _TestFunction($CaseNumber) Case $avArray[2][0] $CaseNumber = "2" _TestFunction($CaseNumber) Case $avArray[3][0] $CaseNumber = "3" _TestFunction($CaseNumber) Case $avArray[4][0] $CaseNumber = "4" _TestFunction($CaseNumber) Case $avArray[5][0] $CaseNumber = "5" _TestFunction($CaseNumber) Case $avArray[6][0] $CaseNumber = "6" _TestFunction($CaseNumber) Case $avArray[7][0] $CaseNumber = "7" _TestFunction($CaseNumber) Case $avArray[8][0] $CaseNumber = "8" _TestFunction($CaseNumber) Case $avArray[9][0] $CaseNumber = "9" _TestFunction($CaseNumber) Case $avArray[10][0] $CaseNumber = "10" _TestFunction($CaseNumber) Case $avArray[11][0] $CaseNumber = "11" _TestFunction($CaseNumber) Case $avArray[12][0] $CaseNumber = "12" _TestFunction($CaseNumber) Case $avArray[13][0] $CaseNumber = "13" _TestFunction($CaseNumber) EndSwitch WEnd Func _TestFunction($CaseNumber) $i = $CaseNumber msgbox(0,"App " & $CaseNumber, "Application " & $AutoAppList[$i] & ' Install Script "' & $avArray[$i][1] & '" goes here') $CaseNumber = 0 EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted August 6, 2008 Share Posted August 6, 2008 Maybe... expandcollapse popupWhile $GUI <> "QUIT" $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Case $AutoQuit Exit Case $ManualQuit Exit Case $AutoUpdateINI msgbox(4096,"Hold on!", "Not done yet") Case $ManualUpdateINI msgbox(4096,"Hold on!", "Not done yet") ;~ Case $avArray[1][0] ;~ $CaseNumber = "1" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[2][0] ;~ $CaseNumber = "2" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[3][0] ;~ $CaseNumber = "3" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[4][0] ;~ $CaseNumber = "4" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[5][0] ;~ $CaseNumber = "5" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[6][0] ;~ $CaseNumber = "6" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[7][0] ;~ $CaseNumber = "7" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[8][0] ;~ $CaseNumber = "8" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[9][0] ;~ $CaseNumber = "9" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[10][0] ;~ $CaseNumber = "10" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[11][0] ;~ $CaseNumber = "11" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[12][0] ;~ $CaseNumber = "12" ;~ _TestFunction($CaseNumber) ;~ Case $avArray[13][0] ;~ $CaseNumber = "13" ;~ _TestFunction($CaseNumber) For $i = 1 to UBound($avArray) -1 If $nMsg = $avArray[$i][0] Then _TestFunction($i) Sleep(1) Next EndSwitch WEnd 8) Link to comment Share on other sites More sharing options...
Wader Posted August 6, 2008 Author Share Posted August 6, 2008 (edited) I tried it out and it didn't work. Nothing happens at all when I click the buttons now. Appreciate the suggestion though. I am willing to try anything. Edited August 6, 2008 by Wader Link to comment Share on other sites More sharing options...
Wader Posted August 7, 2008 Author Share Posted August 7, 2008 Valuater - Your post actually made it clear. The below code is now working with a modification to the Case Statement. I really appreciate it! expandcollapse popup#include <array.au3> Dim $GUI_DOCKHEIGHT, $GUI_DOCKWIDTH, $GUI_EVENT_CLOSE, $Label1, $Label2, $Manual, $GUI Dim $Application1, $Application2, $Application3, $Application4, $Application5, $Application6, $Application7, $Application8, $Application9, $Application10 Dim $ManualAutoInstall, $ManualAutoInstall1, $ManualAutoInstall2, $ManualAutoInstall3, $ManualAutoInstall4, $ManualAutoInstall5, $ManualAutoInstall6, $ManualAutoInstall7, $ManualAutoInstall8, $ManualAutoInstall9, $ManualAutoInstall10 Dim $AutoAutoInstall, $AutoAutoInstall1, $AutoAutoInstall2,$AutoAutoInstall3,$AutoAutoInstall4, $AutoAutoInstall5, $AutoAutoInstall6, $AutoAutoInstall7, $AutoAutoInstall8, $AutoAutoInstall9, $AutoAutoInstall10 Dim $AppButtons, $CaseNumber $AppInstall = GUICreate(IniRead("applicationstest.ini","GUIConfig","GuiTitle",""), IniRead("applicationstest.ini","GUIConfig","GuiWidth",""), IniRead("applicationstest.ini","GUIConfig","GuiHeight",""), IniRead("applicationstest.ini","GUIConfig","GUILeft",""), IniRead("applicationstest.ini","GUIConfig","GUITop","")) $Auto = GUICtrlCreateTab(IniRead("applicationstest.ini","GUIConfig","TabLeft",""), IniRead("applicationstest.ini","GUIConfig","TabTop",""), IniRead("applicationstest.ini","GUIConfig","TabWidth",""), IniRead("applicationstest.ini","GUIConfig","TabHeight","")) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) #Region Tab1 - Auto Apps $Auto = GUICtrlCreateTabItem("Auto") $AutoAppList = IniReadSectionNames("applicationstest.ini") Global $avArray[1000][1000] $RadioHeight = 150 For $i = 1 to $AutoAppList[0] $ApplicationName = IniRead("applicationstest.ini",$AutoAppList[$i],"Name","") $ApplicationDistribMode = IniRead("applicationstest.ini",$AutoAppList[$i],"DistributionMode","") $ApplicationInstallScript = IniRead("applicationstest.ini",$AutoAppList[$i],"InstallScript","") $avArray[$i][0] = $AutoAppList[$i] $avArray[$i][1] = $ApplicationInstallScript If $ApplicationDistribMode = "Auto" Then $AutoAppListName = GUICtrlCreateLabel($ApplicationName, 30, $RadioHeight, 140, 17) If $ApplicationDistribMode = "Auto" AND $ApplicationInstallScript <> "" Then $avArray[$i][0] = GUICtrlCreateButton("Auto Install", 245, $RadioHeight, 75, 17) If $ApplicationDistribMode = "Auto" Then $RadioHeight = $RadioHeight + 20 Next $AutoQUITTop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $AutoUPDATETop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $AutoUpdateINI = GUICtrlCreateButton("UPDATE", 375, $AutoUPDATETop, 100, 25) $AutoQuit = GUICtrlCreateButton("QUIT", 485, $AutoQUITTop, 100, 25) #EndRegion #Region Tab2 - Manual Apps $Manual = GUICtrlCreateTabItem("Manual") $ManualAppList = IniReadSectionNames("applicationstest.ini") $RadioHeight = 150 For $j = 2 to $ManualAppList[0] $AppID = $j $ApplicationName = IniRead("applicationstest.ini",$ManualAppList[$j],"Name","") $ApplicationDistribMode = IniRead("applicationstest.ini",$ManualAppList[$j],"DistributionMode","") $ApplicationInstallScript = IniRead("applicationstest.ini",$ManualAppList[$j],"InstallScript","") $avArray[$i][0] = $ManualAppList[$j] $avArray[$i][1] = $ApplicationInstallScript If $ApplicationDistribMode = "Manual" Then $ManualAppList[$j] = GUICtrlCreateLabel($ApplicationName, 30, $RadioHeight, 140, 17) If $ApplicationDistribMode = "Manual" AND $ApplicationInstallScript <> "" Then $avArray[$j][0] = GUICtrlCreateButton("AutoInstall", 245, $RadioHeight, 75, 17) If $ApplicationDistribMode = "Manual" Then $RadioHeight = $RadioHeight + 20 $ManualAutoInstall = $ManualAutoInstall & $AppID Next $ManualQUITTop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $ManualUPDATETop=IniRead("applicationstest.ini","GUIConfig","TabHeight","")+75 $ManualUpdateINI = GUICtrlCreateButton("UPDATE", 375, $ManualUPDATETop, 100, 25) $ManualQuit = GUICtrlCreateButton("QUIT", 485, $ManualQUITTop, 100, 25) #EndRegion GUICtrlCreateTabItem("") $Header = GUICtrlCreateLabel(IniRead("applicationstest.ini","GUIConfig","Title",""), IniRead("applicationstest.ini","GUIConfig","TitleLeft",""), IniRead("applicationstest.ini","GUIConfig","TitleDown",""), IniRead("applicationstest.ini","GUIConfig","TitleWidth",""), IniRead("applicationstest.ini","GUIConfig","TitleHeight","")) GUICtrlSetFont(-1, 20, 800, 0, "Arial Black") $Intro = GUICtrlCreateLabel(IniRead("applicationstest.ini","GUIConfig","Info",""), 20, 56, 600, 55) GUISetState(@SW_SHOW) While $GUI <> "QUIT" $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Case $AutoQuit Exit Case $ManualQuit Exit Case $AutoUpdateINI msgbox(4096,"Hold on!", "Not done yet") Case $ManualUpdateINI msgbox(4096,"Hold on!", "Not done yet") Case $avArray[1][0] to UBound($avArray) For $i = 1 to UBound($avArray) -1 If $nMsg = $avArray[$i][0] Then $CaseNumber = $i _TestFunction($i) EndIf Next EndSwitch WEnd Func _TestFunction($CaseNumber) $i = $CaseNumber msgbox(0,"App " & $CaseNumber, "Application " & $AutoAppList[$i] & ' Install Script "' & $avArray[$i][1] & '" goes here') $CaseNumber = 0 EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted August 7, 2008 Share Posted August 7, 2008 (edited) Maybe, just a lttle cleaner, removed many of the unnecessary dim statements ( they use memory ) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> Dim $GUI, $ManualAutoInstall ;Dim $Label1, $Label2, $Manual, $GUI ;Dim $Application1, $Application2, $Application3, $Application4, $Application5, $Application6, $Application7, $Application8, $Application9, $Application10 ;Dim $ManualAutoInstall, $ManualAutoInstall1, $ManualAutoInstall2, $ManualAutoInstall3, $ManualAutoInstall4, $ManualAutoInstall5, $ManualAutoInstall6, $ManualAutoInstall7, $ManualAutoInstall8, $ManualAutoInstall9, $ManualAutoInstall10 ; Dim $AutoAutoInstall, $AutoAutoInstall1, $AutoAutoInstall2, $AutoAutoInstall3, $AutoAutoInstall4, $AutoAutoInstall5, $AutoAutoInstall6, $AutoAutoInstall7, $AutoAutoInstall8, $AutoAutoInstall9, $AutoAutoInstall10 ;Dim $AppButtons, $CaseNumber $AppInstall = GUICreate(IniRead("applicationstest.ini", "GUIConfig", "GuiTitle", ""), IniRead("applicationstest.ini", "GUIConfig", "GuiWidth", ""), IniRead("applicationstest.ini", "GUIConfig", "GuiHeight", ""), IniRead("applicationstest.ini", "GUIConfig", "GUILeft", ""), IniRead("applicationstest.ini", "GUIConfig", "GUITop", "")) $Auto = GUICtrlCreateTab(IniRead("applicationstest.ini", "GUIConfig", "TabLeft", ""), IniRead("applicationstest.ini", "GUIConfig", "TabTop", ""), IniRead("applicationstest.ini", "GUIConfig", "TabWidth", ""), IniRead("applicationstest.ini", "GUIConfig", "TabHeight", "")) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) #Region Tab1 - Auto Apps $Auto = GUICtrlCreateTabItem("Auto") $AutoAppList = IniReadSectionNames("applicationstest.ini") Global $avArray[1000][1000] $RadioHeight = 150 For $i = 1 To $AutoAppList[0] $ApplicationName = IniRead("applicationstest.ini", $AutoAppList[$i], "Name", "") $ApplicationDistribMode = IniRead("applicationstest.ini", $AutoAppList[$i], "DistributionMode", "") $ApplicationInstallScript = IniRead("applicationstest.ini", $AutoAppList[$i], "InstallScript", "") $avArray[$i][0] = $AutoAppList[$i] $avArray[$i][1] = $ApplicationInstallScript If $ApplicationDistribMode = "Auto" Then $AutoAppListName = GUICtrlCreateLabel($ApplicationName, 30, $RadioHeight, 140, 17) If $ApplicationDistribMode = "Auto" And $ApplicationInstallScript <> "" Then $avArray[$i][0] = GUICtrlCreateButton("Auto Install", 245, $RadioHeight, 75, 17) If $ApplicationDistribMode = "Auto" Then $RadioHeight = $RadioHeight + 20 Next $AutoQUITTop = IniRead("applicationstest.ini", "GUIConfig", "TabHeight", "") + 75 $AutoUPDATETop = IniRead("applicationstest.ini", "GUIConfig", "TabHeight", "") + 75 $AutoUpdateINI = GUICtrlCreateButton("UPDATE", 375, $AutoUPDATETop, 100, 25) $AutoQuit = GUICtrlCreateButton("QUIT", 485, $AutoQUITTop, 100, 25) #EndRegion Tab1 - Auto Apps #Region Tab2 - Manual Apps $Manual = GUICtrlCreateTabItem("Manual") $ManualAppList = IniReadSectionNames("applicationstest.ini") $RadioHeight = 150 For $j = 2 To $ManualAppList[0] $AppID = $j $ApplicationName = IniRead("applicationstest.ini", $ManualAppList[$j], "Name", "") $ApplicationDistribMode = IniRead("applicationstest.ini", $ManualAppList[$j], "DistributionMode", "") $ApplicationInstallScript = IniRead("applicationstest.ini", $ManualAppList[$j], "InstallScript", "") $avArray[$i][0] = $ManualAppList[$j] $avArray[$i][1] = $ApplicationInstallScript If $ApplicationDistribMode = "Manual" Then $ManualAppList[$j] = GUICtrlCreateLabel($ApplicationName, 30, $RadioHeight, 140, 17) If $ApplicationDistribMode = "Manual" And $ApplicationInstallScript <> "" Then $avArray[$j][0] = GUICtrlCreateButton("AutoInstall", 245, $RadioHeight, 75, 17) If $ApplicationDistribMode = "Manual" Then $RadioHeight = $RadioHeight + 20 $ManualAutoInstall = $ManualAutoInstall & $AppID Next $ManualQUITTop = IniRead("applicationstest.ini", "GUIConfig", "TabHeight", "") + 75 $ManualUPDATETop = IniRead("applicationstest.ini", "GUIConfig", "TabHeight", "") + 75 $ManualUpdateINI = GUICtrlCreateButton("UPDATE", 375, $ManualUPDATETop, 100, 25) $ManualQuit = GUICtrlCreateButton("QUIT", 485, $ManualQUITTop, 100, 25) #EndRegion Tab2 - Manual Apps GUICtrlCreateTabItem("") $Header = GUICtrlCreateLabel(IniRead("applicationstest.ini", "GUIConfig", "Title", ""), IniRead("applicationstest.ini", "GUIConfig", "TitleLeft", ""), IniRead("applicationstest.ini", "GUIConfig", "TitleDown", ""), IniRead("applicationstest.ini", "GUIConfig", "TitleWidth", ""), IniRead("applicationstest.ini", "GUIConfig", "TitleHeight", "")) GUICtrlSetFont(-1, 20, 800, 0, "Arial Black") $Intro = GUICtrlCreateLabel(IniRead("applicationstest.ini", "GUIConfig", "Info", ""), 20, 56, 600, 55) GUISetState(@SW_SHOW) While $GUI <> "QUIT" $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $AutoQuit, $ManualQuit Exit Case $AutoUpdateINI MsgBox(4096, "Hold on!", "Not done yet") Case $ManualUpdateINI MsgBox(4096, "Hold on!", "Not done yet") Case $avArray[1][0] To UBound($avArray) For $i = 1 To UBound($avArray) - 1 If $nMsg = $avArray[$i][0] Then ;$CaseNumber = $i _TestFunction($i) EndIf Next EndSwitch WEnd Func _TestFunction($CaseNumber) ;$i = $CaseNumber MsgBox(0, "App " & $CaseNumber, "Application " & $AutoAppList[$i] & ' Install Script "' & $avArray[$i][1] & '" goes here') ;$CaseNumber = 0 EndFunc ;==>_TestFunction. The includes I added are necessary for other things to function... note the $GUI_EVENT_CLOSE 8) Edited August 7, 2008 by Valuater Link to comment Share on other sites More sharing options...
Wader Posted August 7, 2008 Author Share Posted August 7, 2008 Thanks again. I cleaned up my script on my end now. I always forget to do that. Link to comment Share on other sites More sharing options...
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