StMaSi Posted February 20, 2017 Posted February 20, 2017 So, I have a text file like this... "Label", {left}, {top}, {width}, {height} "Label", {left}, {top}, {width}, {height} "Label", {left}, {top}, {width}, {height} "Label", {left}, {top}, {width}, {height} "Label", {left}, {top}, {width}, {height} What I'm attempting to do is read the data from this file, into an array, and use it to create checkboxes on a form like this... For $cb = 0 to 4 ; line numbers $Checkbox[$cb] = GUICtrlCreateCheckbox({label}, {left}, {top}, {width}, {height}) Next However, I can't figure out how to read the file into the array so as to be able to assign the data elements appropriately. I'm obviously missing something (or more than likely more than one something), but can't figure it out. Can anyone assist with this? Thanx.
Subz Posted February 20, 2017 Posted February 20, 2017 Do you mean something like this: #Include <Array.au3> #include <File.au3> Local $aFileRead, $aStringSplit, $aGui[0][5] _FileReadToArray('Gui.txt', $aFileRead) For $i = 1 To $aFileRead[0] $aStringSplit = StringSplit($aFileRead[$i], ',', 2) _ArrayTranspose($aStringSplit) _ArrayAdd($aGui, $aStringSplit) Next _ArrayDisplay($aGui)
StMaSi Posted February 20, 2017 Author Posted February 20, 2017 Yes, that creates the array perfectly. Now, if I were to use the GUICtrlCreateCheckBox() within that piece of code, I think I would insert it right before the next, correct? Or, do I now need another looper to read the array and create the checkboxes? Thanx again!
Subz Posted February 20, 2017 Posted February 20, 2017 Technically you don't need the array, you can just use: #Include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $aFileRead, $aStringSplit GUICreate('', 200, 110) _FileReadToArray('Gui.txt', $aFileRead) For $i = 1 To $aFileRead[0] $aStringSplit = StringSplit($aFileRead[$i], ',', 2) If UBound($aStringSplit) -1 = 4 Then GUICtrlCreateCheckbox($aStringSplit[0], Number($aStringSplit[1]), Number($aStringSplit[2]), Number($aStringSplit[3]), Number($aStringSplit[4])) EndIf Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Gui.txt "Label1", 5, 5, 190, 20 "Label2", 5, 25, 190, 20 "Label3", 5, 45, 190, 20 "Label4", 5, 65, 190, 20 "Label5", 5, 85, 190, 20
StMaSi Posted February 20, 2017 Author Posted February 20, 2017 Excellent! Just what the Dr. ordered. Thank you so much!!!
StMaSi Posted February 21, 2017 Author Posted February 21, 2017 Dang. With the checkboxes being created in this manner, how on earth would I be able to tell which ones are checked? The goal is to have the user select one or more options, then the script would install their choices like this... Would I have to create a label/tag for each checkbox during their creation, or something along those lines, so as to be able to target them afterward? Thanx.
Subz Posted February 21, 2017 Posted February 21, 2017 (edited) You could do it a few ways for example: 1. add another column with an Array Name for example: Adobe_Flash_Player, label, x, y, w, h, then you can use the Assign function. 2. Use the original array to assign the variable for example: $FileRead[$i] = GUICtrlCreateCheckbox($aStringSplit[0], Number($aStringSplit[1]), Number($aStringSplit[2]), Number($aStringSplit[3]), Number($aStringSplit[4])) Either way you can then use these to capture there states when you click Install. Edited February 21, 2017 by Subz
StMaSi Posted February 21, 2017 Author Posted February 21, 2017 So, I can't seem to get the Assign function to work. Is it because I'm attempting to utilize one of the array elements? Thanx.
Subz Posted February 21, 2017 Posted February 21, 2017 Not sure it works for me: #Include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $aFileRead, $aStringSplit GUICreate('', 205, 135) _FileReadToArray('Gui.txt', $aFileRead) Local $aFileItem[$aFileRead[0]] For $i = 1 To $aFileRead[0] $aStringSplit = StringSplit($aFileRead[$i], ',', 2) If UBound($aStringSplit) -1 = 5 Then Assign($aStringSplit[0], GUICtrlCreateCheckbox($aStringSplit[1], Number($aStringSplit[2]), Number($aStringSplit[3]), Number($aStringSplit[4]), Number($aStringSplit[5]))) $aFileItem[$i - 1] = $aStringSplit[0] EndIf Next $hCancel = GUICtrlCreateButton('Cancel', 5, 105, 95, 25) $hInstall = GUICtrlCreateButton('Install', 105, 105, 95, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hCancel ExitLoop Case $hInstall For $i = 0 To UBound($aFileItem) - 1 If GUICtrlRead(Eval($aFileItem[$i])) = $GUI_CHECKED Then ConsoleWrite('IsChecked : ' & $aFileItem[$i] & @CRLF) EndIf Next EndSwitch WEnd Ini File Var1, Label 1, 5, 5, 190, 20 Var2, Label 2, 5, 25, 190, 20 Var3, Label 3, 5, 45, 190, 20 Var4, Label 4, 5, 65, 190, 20 Var5, Label 5, 5, 85, 190, 20
StMaSi Posted February 21, 2017 Author Posted February 21, 2017 I was close to your suggestion here, but no cigar. I modified my code to reflect your code, but swapped a MsgBox for your ConsoleWrite and now I can see the "Var#" label in the MsgBox. However, if the "Var#" value contains a period, then nothing occurs when I click the Install button. Is there a reason a period can't be within the variable value? Thanx again.
Subz Posted February 21, 2017 Posted February 21, 2017 https://www.autoitscript.com/autoit3/docs/intro/lang_variables.htm
Malkey Posted February 22, 2017 Posted February 22, 2017 This modified Subz's example automates the checkbox positions on the GUI, so that the positions are not required to be stored in the ini file. #include <GUIConstantsEx.au3> Local $aFileRead = ["Label 1", "Label 2", "Label 3", "Label 4", "Label 5"] ; Or ;Local $aFileRead = FileReadToArray('Gui.txt') Local $aID_CkBx[UBound($aFileRead)], $sResults GUICreate('', 205, 135) For $i = 0 To UBound($aID_CkBx) - 1 $aID_CkBx[$i] = GUICtrlCreateCheckbox($aFileRead[$i], 5, (20 * $i) + 5, 190, 20) ; 1 column, many rows. ; Or ;$aID_CkBx[$i] = GUICtrlCreateCheckbox($aFileRead[$i], 5 + (Int($i / 3) * 95), ((20 * Mod($i, 3)) + 5), 95, 20) ; 3 rows, many columns. Next Local $hCancel = GUICtrlCreateButton('Cancel', 5, 105, 95, 25) Local $hInstall = GUICtrlCreateButton('Install', 105, 105, 95, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hCancel ExitLoop Case $hInstall For $i = 0 To UBound($aID_CkBx) - 1 If GUICtrlRead($aID_CkBx[$i]) = $GUI_CHECKED Then $sResults &= $aFileRead[$i] & ' is checked.' & @CRLF EndIf Next MsgBox(0, "Results", $sResults) $sResults = "" EndSwitch WEnd 'Gui.txt' - The ini file used, if needed. (The labels could be store in an array in the script.) Label 1 Label 2 Label 3 Label 4 Label 5 You don't have to use this method, it's just an alternative that could come in handy one day.
Subz Posted September 17, 2019 Posted September 17, 2019 Thought I'd post answers to your pm here: Create an in for example Installations.ini [Installations] Adobe Acrobat = Msiexec.exe /i <Path to Msi> /QN /NoRestart Microsoft Office = Setup.exe /adminfile MSOfffice.msp Use something like the following to allow users to create custom batch script: expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $g_sInstalls = @ScriptDir & "\Installs.cmd" Global $g_aInstallations = IniReadSection(@ScriptDir & "\Installations.ini", "Installations") If @error Then Exit MsgBox(4096, "Error", "Error Reading [Installations] Section") ;~ Lets add another column for Checkbox id _ArrayColInsert($g_aInstallations, 0) Example() Func Example() Local $iTop = 10, $iBottom = 10, $iY = 10, $iHeight = 25 Local $hGUI = GUICreate("Installations", 300, $iTop + ($g_aInstallations[0][1] * $iHeight) + $iHeight + $iBottom) For $i = 1 To $g_aInstallations[0][1] $g_aInstallations[$i][0] = GUICtrlCreateCheckbox($g_aInstallations[$i][1], 10, $iY, 185, $iHeight) $iY += 25 Next Local $idButton_Close = GUICtrlCreateButton("Close", 210, $iY, 85, $iHeight) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $g_aInstallations[1][0] To $g_aInstallations[$g_aInstallations[0][1]][0] $hInstalls = FileOpen($g_sInstalls, 10) For $i = 1 To $g_aInstallations[0][1] If _IsChecked($g_aInstallations[$i][0]) Then FileWrite($hInstalls, $g_aInstallations[$i][2] & @CRLF) EndIf Next FileClose($hInstalls) EndSwitch WEnd EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked
Subz Posted September 18, 2019 Posted September 18, 2019 @DonJK Check that when you copied from the forum that it didn't include any hidden characters (use notepad++) Make sure that the file "Installations.ini" is saved into the same directory as the script, please post results from the Scite output console if you're still getting errors and please use the forum rather than pm.
DonJK Posted September 18, 2019 Posted September 18, 2019 (edited) @Subz thank you! This was helpful Edited October 3, 2019 by DonJK
DonJK Posted November 7, 2019 Posted November 7, 2019 @Subz is there a way to include a combo box with this? So that the checkbox options vary depending on what is selected in the combo box?
Nine Posted November 7, 2019 Posted November 7, 2019 Yes of course. Could you describe what's appearing in the comboBox and what the options in checkBox should be ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
DonJK Posted December 3, 2019 Posted December 3, 2019 If you had a combo box it would be filled with states and the when you select a state it would reveal the attractions associated with that state. For the New York dropdown the checkboxes would be the Statue if Liberty, Time Square, and the Brooklyn Bridge. California would be Disneyland, Golden gate Bridge and Alcatraz.
Nine Posted December 3, 2019 Posted December 3, 2019 Here to get you started : #include <GUIConstants.au3> Local $aStates[] = ["New York", "California"] Local $aAttractions[][] = [["Statue of Liberty", "Time Square", "Brooklyn Bridge"], ["Disneyland", "Golden gate Bridge", "Alcatraz"]] GUICreate('List of attractions', 250, 250) Local $idCombo = GUICtrlCreateCombo("", 10, 30, 80, 28) For $i = 0 To UBound($aStates) - 1 GUICtrlSetData($idCombo, $aStates[$i]) Next Local $aCB[UBound($aAttractions, 2)] For $i = 0 To UBound($aAttractions, 2) - 1 $aCB[$i] = GUICtrlCreateCheckbox("", 110, 10 + $i * 30, 100, 25) GUICtrlSetState(-1, $GUI_HIDE) Next GUISetState() Local $iState While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idCombo $iState = CheckState(GUICtrlRead($idCombo)) For $i = 0 To UBound($aAttractions, 2) - 1 GUICtrlSetData($aCB[$i], $aAttractions[$iState][$i]) GUICtrlSetState($aCB[$i], $GUI_SHOW + $GUI_UNCHECKED) Next EndSwitch WEnd Func CheckState($sState) For $i = 0 To UBound($aStates) - 1 If $aStates[$i] = $sState Then Return $i Next EndFunc ;==>CheckState Ujube 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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