InnocentRain Posted June 8, 2022 Share Posted June 8, 2022 Hey Guys, i am currently trying to code a little program that connects certain nas drives to the user based on what checkboxes the user checks. This is necessary so that the users also get connected to the drives when connected to the network via vpn. The program works by first reading all currently connected drives while the user is connected normally. This means that i have to generate the Checkboxes dynamicly because not all users have access to the same amount of drives and there are also department specific drives. I currently write all drives to a ini file, then make an array out of it with Local $Drives_Array = IniReadSectionNames("config.ini") I then go through the array and create all Checkboxes and also already check them if they were checked before For $i = 1 to $Drives_Array[0] $Drive = $Drives_Array[$i] ; Because the Variable gets redefined below $Name = IniRead("config.ini", $Drives_Array[$i], "Name", "Default Value") $Drives_Array[$i] = GUICtrlCreateCheckbox($Name, 0, ($i * 35), 140, 30) GUICtrlSetFont($Drives_Array[$i], 20, 0, 0, "Calibri") GUICtrlSetColor($Drives_Array[$i], 0x225588) If IniRead("saveddrives.ini", "Drives", $Drive, "Default Value") == "Connect" Then GUICtrlSetState($Drives_Array[$i], $GUI_CHECKED) EndIf ConsoleWrite($Drives_Array[$i]) Next I am now trying to read the state of the checkboxes when the User presses the "connect" button but i cant get the hang of it... The idea is to write it to the "saveddrives.ini" and then connect them with another function that already works so that it can be checked if it was connected when the program gets used the next time. If i now try to get the state of it with Func Save_Drives() FileDelete("saveddrives.ini") _FileCreate("saveddrives.ini") FileWriteLine("saveddrives.ini", "[Drives]") Local $Drives_Array_2 = IniReadSectionNames("config.ini") For $i = 1 to $Drives_Array_2[0] If GUICtrlRead($Drives_Array_2[$i]) = $GUI_CHECKED Then FileWriteLine("saveddrives.ini", $Drives_Array_2[$i] & "=Connect") Else FileWriteLine("saveddrives.ini", $Drives_Array_2[$i] & "=Disconnect") EndIf Next EndFunc it shows all checkboxes as not checked. The reason i use $Drives_Array_2 is because i get problems when making it a global variable above. If i ConsoleWrite $Drives_Array[$i] and $Drives_Array_2[$i] they are the same(i.e. H:) Thanks for your help in advance. Link to comment Share on other sites More sharing options...
InnocentRain Posted June 8, 2022 Author Share Posted June 8, 2022 Here i have the entire program if its easier to understand. Just put all three files into a folder and run it Nas Connector 2.0.au3 GUIScrollbars_Ex.au3 Link to comment Share on other sites More sharing options...
Subz Posted June 8, 2022 Share Posted June 8, 2022 Can you post your ini file? Link to comment Share on other sites More sharing options...
InnocentRain Posted June 8, 2022 Author Share Posted June 8, 2022 1 minute ago, Subz said: Can you post your ini file? Of course, the File gets automaticly generated with the Drive Letter, Path, Name and the Letter as the Section Nameconfig.ini Link to comment Share on other sites More sharing options...
Solution Subz Posted June 8, 2022 Solution Share Posted June 8, 2022 You actually overwrite the values of $Drive_Array when you use GuiCtrlCreateCheckBox, here is how I'd do it, although there are otherways: Create 2d Array for $Drives_Array Global $Drives_Array = IniReadSectionNames("config.ini") ;~ Add Array Column ControlId _ArrayColInsert($Drives_Array, 0) ;~ Add Array Column Name _ArrayColInsert($Drives_Array, 2) For $i = 1 to UBound($Drives_Array) - 1 ;~ $Drives_Array[$i][0] = ControlId ;~ $Drives_Array[$i][1] = Drive example H: ;~ $Drives_Array[$i][2] = Drive Name $Drives_Array[$i][2] = IniRead("config.ini", $Drives_Array[$i][1], "Name", "Default Value") $Drives_Array[$i][0] = GUICtrlCreateCheckbox($Drives_Array[$i][2], 0, ($i * 35), 140, 30) GUICtrlSetFont($Drives_Array[$i][0], 20, 0, 0, "Calibri") GUICtrlSetColor($Drives_Array[$i][0], 0x225588) If IniRead("saveddrives.ini", "Drives", $Drives_Array[$i][1], "Default Value") == "Connect" Then GUICtrlSetState($Drives_Array[$i][0], $GUI_CHECKED) EndIf Next You can then save using the following function: Func Save_Drives() FileDelete("saveddrives.ini") ;~ Loop through GuiControlCreateCheckBox ControlIds For $i = 1 To UBound($Drives_Array)-1 If GUICtrlRead($Drives_Array[$i][0]) = $GUI_CHECKED Then IniWrite("saveddrives.ini", "Drives", $Drives_Array[$i][1], "Connect") Else IniWrite("saveddrives.ini", "Drives", $Drives_Array[$i][1], "Disconnect") EndIf Next EndFunc InnocentRain 1 Link to comment Share on other sites More sharing options...
InnocentRain Posted June 8, 2022 Author Share Posted June 8, 2022 33 minutes ago, Subz said: You actually overwrite the values of $Drive_Array when you use GuiCtrlCreateCheckBox, here is how I'd do it, although there are otherways: Create 2d Array for $Drives_Array Global $Drives_Array = IniReadSectionNames("config.ini") ;~ Add Array Column ControlId _ArrayColInsert($Drives_Array, 0) ;~ Add Array Column Name _ArrayColInsert($Drives_Array, 2) For $i = 1 to UBound($Drives_Array) - 1 ;~ $Drives_Array[$i][0] = ControlId ;~ $Drives_Array[$i][1] = Drive example H: ;~ $Drives_Array[$i][2] = Drive Name $Drives_Array[$i][2] = IniRead("config.ini", $Drives_Array[$i][1], "Name", "Default Value") $Drives_Array[$i][0] = GUICtrlCreateCheckbox($Drives_Array[$i][2], 0, ($i * 35), 140, 30) GUICtrlSetFont($Drives_Array[$i][0], 20, 0, 0, "Calibri") GUICtrlSetColor($Drives_Array[$i][0], 0x225588) If IniRead("saveddrives.ini", "Drives", $Drives_Array[$i][1], "Default Value") == "Connect" Then GUICtrlSetState($Drives_Array[$i][0], $GUI_CHECKED) EndIf Next You can then save using the following function: Func Save_Drives() FileDelete("saveddrives.ini") ;~ Loop through GuiControlCreateCheckBox ControlIds For $i = 1 To UBound($Drives_Array)-1 If GUICtrlRead($Drives_Array[$i][0]) = $GUI_CHECKED Then IniWrite("saveddrives.ini", "Drives", $Drives_Array[$i][1], "Connect") Else IniWrite("saveddrives.ini", "Drives", $Drives_Array[$i][1], "Disconnect") EndIf Next EndFunc Thank you so much! You helped me out a lot! 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