Necromorph Posted April 1, 2010 Share Posted April 1, 2010 (edited) okay, here is what i need to do, i have a .txt with all the usernames i manage and assist. i _FileReadToArray() that for my combobox drop down, but i want to be able to delete a user out of there with a 'delete' button. and after that does that, i need it to 'refresh' the combobox drop down so the user is 'gone'. here is what i have: Global $users = "C:\ProgramData\tmPCSolutions\Users.txt" $labelUserName = GUICtrlCreateLabel("user assisted", 200, 25) $comboUserName = GUICtrlCreateCombo("none", 200, 47.5, 150, -1, $CBS_DROPDOWNLIST) GUICtrlSetData($comboUserName, "none", default) Dim $displayUsers _FileReadToArray($users, $displayUsers) _ArraySort($displayUsers) For $varUsers = 1 to $displayUsers[0] GUICtrlSetData($comboUserName, $displayUsers[$varUsers]) Next $buttonDeleteUser = GUICtrlCreateButton("delete user", 275, 75, 75) While 1 $msg = GUIGetMsg() Switch $msg Case $buttonDeleteUser If GUICtrlRead($comboUserName) = "none" Then MsgBox(48, "redLabel timeKeeper", "you cannot delete the 'none' entry!") Else $msgboxDeleteUser = MsgBox(36, "redLabel timeKeeper", "would you like to delete the selected user?" & @CRLF & "'" & GUICtrlRead($comboUserName) & "'") If $msgboxDeleteUser = 6 Then ;==> i need code here to delete the selected user in the combobox, and refresh the userlist ; EndIf EndIf EndSwitch Wend i was think it needs to $newArray = _arraydelete($selectedUser) then $newUserlist = _arrayWriteToFile($newArray) then GUICtrlSetState($comboUsername, $newUserList), but this doens't quite happen like that. thanks. Edited April 1, 2010 by redLabel Link to comment Share on other sites More sharing options...
martin Posted April 1, 2010 Share Posted April 1, 2010 (edited) Is _GUICtrlComboBox_DeleteString what you need? Edited April 1, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Fire Posted April 1, 2010 Share Posted April 1, 2010 BTW this works with wmic. Please be carefull with your accounts when using this script. expandcollapse popup#RequireAdmin #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Dim $avarray _FileReadToArray(@ScriptDir&"\users.txt",$avarray) _ArraySort($avarray) $Form1 = GUICreate("Form1", 398, 217, -1,-1) $Combo1 = GUICtrlCreateCombo("", 96, 48, 185, 25, $CBS_DROPDOWNLIST) For $i=1 To $avarray[0] GUICtrlSetData($Combo1,$avarray[$i]) Next $Button1 = GUICtrlCreateButton("Delete", 136, 152, 89, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;deleting RunWait("cmd.exe /c " & "net user " & GUICtrlRead($Combo1) & " /delete",@ScriptDir,@SW_HIDE) RunWait("cmd.exe /c " & "wmic USERACCOUNT get Name >"&@ScriptDir&"\users.txt",@ScriptDir,@SW_HIDE) _FileReadToArray(@ScriptDir&"\users.txt",$avarray) GUICtrlSetData($Combo1,"") For $i=2 To $avarray[0] GUICtrlSetData($Combo1,$avarray[$i]) Next MsgBox(64,"Complete","Complete",10) EndSwitch WEnd [size="5"] [/size] Link to comment Share on other sites More sharing options...
Necromorph Posted April 1, 2010 Author Share Posted April 1, 2010 thank you much for you reply's i have been working with the GUICtrlComboBox_DeleteString() func, but im running into problems, i am storing the users in a .txt file and then reading from it to populate the combobox array, then i need to delete an entry from it, open the file, erase it's contents, then rewrite the new array (without the deleted user), and then close it. and i just can't get it to work, im wondering if there is another way, or place to keep my "users" inplace of a .txt file. thanks for all the help. #include <GUIConstantsEx.au3> #include <GUIComboBoxEx.au3> #include <ComboConstants.au3> #include <Array.au3> #include <file.au3> GUICreate("", -1, -1) GUISetState() $comboUserNames = GUICtrlCreateCombo('none', 25, 25, 150, -1, $CBS_DROPDOWNLIST) $handleUserNames = GUICtrlGetHandle($comboUserNames) GUICtrlSetData(-1, 'none', Default) $users = "C:\ProgramData\tmPCSolutions\Users - Copy.txt" Dim $userList _FileReadToArray($users, $userList) _ArraySort($userList) For $varUsers = 1 To $userList[0] GUICtrlSetData($comboUserNames, $userList[$varUsers]) Next $buttonDeleteUser = GUICtrlCreateButton("delete user", 25, 75, 75) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $buttonDeleteUser $varDeletedUser = _GUICtrlComboBox_SelectString($handleUserNames, GUICtrlRead($comboUserNames)) _GUICtrlComboBox_DeleteString($handleUserNames, $varDeletedUser) $varNewArray = _GUICtrlComboBoxEx_GetListArray($handleUserNames) $varNewUserArray = _ArrayDelete($varNewArray, 'none' & _ArrayMin($varNewArray)) _FileWriteFromArray($users, $varNewUserArray) FileClose($users) GUICtrlSetData($comboUserNames, 'none') EndSwitch WEnd Link to comment Share on other sites More sharing options...
Necromorph Posted April 1, 2010 Author Share Posted April 1, 2010 i got it to work somewhat, like this: If $msgboxDeleteUser = 6 Then $varDeletedUser = _GUICtrlComboBox_SelectString($handleUserName, GUICtrlRead($comboUserName)) _GUICtrlComboBox_DeleteString($handleUserName, $varDeletedUser) GUICtrlSetData($comboUserName, 'none') $newUserList = _GUICtrlComboBox_GetListArray($handleUserName) _ArrayDelete($newUserList, 0 & 1) FileOpen($users, 2) _FileWriteFromArray($users, $newUserList, 1) FileClose($users) EndIf Link to comment Share on other sites More sharing options...
jclent Posted January 22, 2014 Share Posted January 22, 2014 I had same problem, but answer was way simpler than that..... Delete the combo box, recreate it, reload data, and then SETSTATE User will never see you updated the list. I used a SQL Query, rather than the file, but the answer is the same. GUICtrlDelete($Entity) $Entity = GUICtrlCreateCombo("Select CountID", 10, 10, 200) GUISetState() $sql = " SELECT "; $sql &= " Location "; $sql &= " , CountID "; $sql &= " FROM "; $sql &= " PHYSINV "; $sql &= " WHERE "; $sql &= " CreateDate > '" & _DateAdd('D', -41, @YEAR & "/" & @MON & "/" & @MDAY ) & "' "; $rs = $sqlCon.Execute($sql); $rs.MoveFirst() ; move to the first record Do $p = $rs.getRows(1) ; get next row GUICtrlSetData($Entity, $p[0][1] & ' [' & $p[0][0] & ']' ) ; load entities in window from database. Until $rs.EOF ; until no more rows GUISetState() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2014 Moderators Share Posted January 22, 2014 jclent,No need to delete and recreate the combo. Get the data into a delimited string and start the string with the delimiter - makes it easy to append items as you add them as you can prefix them all with the delimiter. From the Help file: "For Combo or List control :If the "data" corresponds to an already existing entry it is set as the default.If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed"Much cleaner that way. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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