ajenkins Posted December 1, 2014 Share Posted December 1, 2014 (edited) I hope im asking this right. I am trying to cut this script down. expandcollapse popupGlobal $Checkbox1 = GUICtrlCreateCheckbox("3G2", 32, 128, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Checkbox2 = GUICtrlCreateCheckbox("3GP", 32, 152, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Checkbox3 = GUICtrlCreateCheckbox("A52", 32, 176, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Checkbox4 = GUICtrlCreateCheckbox("AAC", 32, 200, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Checkbox5 = GUICtrlCreateCheckbox("AC3", 32, 224, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Checkbox6 = GUICtrlCreateCheckbox("ASF", 32, 248, 97, 17) If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.3G2") RegDelete("HKCR\.3G2") RegWrite("HKCR\.3G2","","REG_SZ",'vlcfile') EndIf If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.3GP") RegDelete("HKCR\.3GP") RegWrite("HKCR\.3GP","","REG_SZ",'vlcfile') EndIf If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.A52") RegDelete("HKCR\.A52") RegWrite("HKCR\.A52","","REG_SZ",'vlcfile') EndIf If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.AAC") RegDelete("HKCR\.AAC") RegWrite("HKCR\.AAC","","REG_SZ",'vlcfile') EndIf If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.AC3") RegDelete("HKCR\.AC3") RegWrite("HKCR\.AC3","","REG_SZ",'vlcfile') EndIf If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ASF") RegDelete("HKCR\.ASF") RegWrite("HKCR\.ASF","","REG_SZ",'vlcfile') EndIf It keeps going until $checkbox59... Each time only changing one small element. I used this to check all checkboxes. For $checkbox = 1 to 59 GUICtrlSetState($Checkbox,$GUI_CHECKED) Next i was thinking I could use something similar, and include my elements into an array But how can I loop through the variables and an array of elements? Edited December 1, 2014 by ajenkins Link to comment Share on other sites More sharing options...
jdelaney Posted December 1, 2014 Share Posted December 1, 2014 You need to move them all into an array: Local $hGUI = GUICreate("Example", 100, 900) ; Create a checkbox control. Local $aCheckboxes[43] $y = 10 For $i = 0 To UBound($aCheckboxes)-1 $aCheckboxes[$i] = GUICtrlCreateCheckbox($i, 10, $y, 50, 15) $y+=20 Next ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) while True For $i = 0 To UBound($aCheckboxes)-1 ControlCommand($hGUI,"",$aCheckboxes[$i],"Check", "") Sleep(50) Next For $i = 0 To UBound($aCheckboxes)-1 ControlCommand($hGUI,"",$aCheckboxes[$i],"UnCheck", "") Sleep(50) Next WEnd IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Solution mikell Posted December 1, 2014 Solution Share Posted December 1, 2014 (edited) And why not a 2D array Global $array[59][2] $array[0][0] = "3G2" $array[0][1] = GUICtrlCreateCheckbox($array[0][0], 32, 128, 97, 17) $array[1][0] = "3GP" $array[1][1] = GUICtrlCreateCheckbox($array[1][0], 32, 152, 97, 17) $array[2][0] = "A52" $array[2][1] = GUICtrlCreateCheckbox($array[2][0], 32, 176, 97, 17) ; etc For $i = 0 to 58 GUICtrlSetState($array[$i][1], $GUI_CHECKED) Next For $i = 0 to 58 If GUICtrlRead($array[$i][1]) = $GUI_CHECKED Then RegDelete("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." & $array[2][0]) RegDelete("HKCR\." & $array[$i][0]) RegWrite("HKCR\." & $array[$i][0],"","REG_SZ",'vlcfile') EndIf Next Edit [typo] Edited December 1, 2014 by mikell Link to comment Share on other sites More sharing options...
ajenkins Posted December 3, 2014 Author Share Posted December 3, 2014 thanks guys, is there a way to write the 2d array in this fasion? i keep getting error for the un-declared variable. any way around it? Global $check_arr[58][2] = [ _ ["3G2", GUICtrlCreateCheckbox($check_arr[0][0], 32, 128, 97, 17)], _ ["3GP",GUICtrlCreateCheckbox($check_arr[1][0], 32, 152, 97, 17)], _ just for learning purposes. if not, i will do it the other way. Link to comment Share on other sites More sharing options...
mikell Posted December 3, 2014 Share Posted December 3, 2014 (edited) Just do it like this Global $check_arr[58][2] = [ _ ["3G2", GUICtrlCreateCheckbox("3G2", 32, 128, 97, 17)], _ ["3GP",GUICtrlCreateCheckbox("3GP", 32, 152, 97, 17)], _ You can't use an array element inside this same array while it's not still declared Edited December 3, 2014 by mikell Link to comment Share on other sites More sharing options...
ajenkins Posted December 3, 2014 Author Share Posted December 3, 2014 thats what i came up with also. thanks for the answers! 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