Necromorph Posted April 3, 2010 Share Posted April 3, 2010 (edited) okay, this is going to be a huge amount of code expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=redLabel_Default.ico #AutoIt3Wrapper_outfile=redLabel timeKeeper.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> #include <GUIComboBoxEx.au3> #include <ComboConstants.au3> #include <Date.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <GUIConstantsEX.au3> #include <GuiDateTimePicker.au3> Global $users = "C:\ProgramData\tmPCSolutions\Users.txt" Global $varDir = "C:\ProgramData\tmPCSolutions\Weekly Logs\" #Region ; mainform gui ; Global $mainForm = GUICreate("redLabel timeKeeper", 375, 450) ; main form ; GUISetState() GUISetIcon(@ScriptDir & "\redLabel_Default.ico") GUICtrlCreateLabel("company name", 25, 25) $comboCompanyName = GUICtrlCreateCombo("all", 25, 47.5, 150, -1, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "advanced electric & controls") GUICtrlSetData(-1, "automated machine systems") GUICtrlSetData(-1, "chariot wind") GUICtrlSetData(-1, "dta enterprises") GUICtrlSetData(-1, "mech-fab industries") GUICtrlCreateLabel("user assisted", 200, 25) $comboUserName = GUICtrlCreateCombo("none", 200, 47.5, 150, -1, $CBS_DROPDOWNLIST) $handleUserName = GUICtrlGetHandle($comboUserName) GUICtrlSetData($comboUserName, 'none') Dim $displayUsers _FileReadToArray($users, $displayUsers) _ArraySort($displayUsers) For $varUsers = 1 To $displayUsers[0] GUICtrlSetData($comboUserName, $displayUsers[$varUsers]) Next $buttonNewUser = GUICtrlCreateButton("new user", 200, 75, 75) $buttonDeleteUser = GUICtrlCreateButton("delete user", 275, 75, 75) GUICtrlCreateLabel("date", 25, 90) $calanderDate = GUICtrlCreateMonthCal("", 25, 110.5, 225, 180) GUICtrlCreateLabel("start time", 275, 110.5) $timeStartTime = GUICtrlCreateDate("", 275, 133, 75, -1, $DTS_TIMEFORMAT) $formatStartTime = GUICtrlGetHandle($timeStartTime) _GUICtrlDTP_SetFormat($formatStartTime, "hh:mm tt") GUICtrlCreateLabel("end time", 275, 175) $timeEndTime = GUICtrlCreateDate("", 275, 197.5, 75, -1, $DTS_TIMEFORMAT) $formatEndTime = GUICtrlGetHandle($timeEndTime) _GUICtrlDTP_SetFormat($formatEndTime, "hh:mm tt") GUICtrlCreateLabel("total time", 275, 242.5) $buttonTotalTime = GUICtrlCreateButton("calc time", 275, 265, 75) GUICtrlCreateLabel("tasks completed", 25, 300) $textboxTasks = GUICtrlCreateInput("", 25, 322.5, 325, 65) $buttonViewLog = GUICtrlCreateButton("view logs", 25, 400, 75) $buttonCancelForm = GUICtrlCreateButton("< &close", 200, 400, 75) $buttonLogEntry = GUICtrlCreateButton("&log entry >", 275, 400, 75) #EndRegion ; mainform gui ; While 1 ; gui event args ; $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $buttonCancelForm Exit Case $buttonTotalTime $varDate = GUICtrlRead($calanderDate) $varStartTime = _24Hour(GUICtrlRead($timeStartTime)) $varEndTime = _24Hour(GUICtrlRead($timeEndTime)) If $varStartTime == $varEndTime Then MsgBox(48, "redLabel timeKeeper", "there is no difference to calculate!") Else $varTotalTime = _DateDiff('n', $varDate & " " & $varStartTime, $varDate & " " & $varEndTime) $totalTime = Round($varTotalTime / 60, 2) GUICtrlSetData($buttonTotalTime, $totalTime & " hours") EndIf Case $buttonNewUser _NewUser() Dim $displayUsers _FileReadToArray($users, $displayUsers) _ArraySort($displayUsers) For $varUsers = 1 To $displayUsers[0] GUICtrlSetData($comboUserName, $displayUsers[$varUsers]) Next GUICtrlSetData($comboUserName, GUICtrlRead($inputNewUser)) 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 this user?" & @CRLF & "'" & GUICtrlRead($comboUserName) & "'") If $msgboxDeleteUser = 6 Then $varDeletedUser = _GUICtrlComboBox_SelectString($handleUserName, GUICtrlRead($comboUserName)) _GUICtrlComboBox_DeleteString($handleUserName, $varDeletedUser) GUICtrlSetData($comboUserName, 'none') $newUserList = _GUICtrlComboBox_GetListArray($handleUserName) _ArrayDelete($newUserList, 1) FileOpen($users, 2) _FileWriteFromArray($users, $newUserList, 1) FileClose($users) EndIf EndIf Case $buttonViewLog _ViewLog() Case $buttonLogEntry If GUICtrlRead($buttonTotalTime) == "calc time" Then MsgBox(48, "redLabel timeKeeper", "you must have a calculated hour value!") Else $msgboxLogEntry = MsgBox(36, "redLabel timeKeeper", "would you like to log this entry?") If $msgboxLogEntry = 6 Then $logFile = _OpenLogFile() FileWriteLine($logFile, @CRLF & "totaltime: " & GUICtrlRead($buttonTotalTime) & @TAB & "date: " & GUICtrlRead($calanderDate)) FileWriteLine($logFile, @TAB & "starttime: " & GUICtrlRead($timeStartTime) & @TAB & "endtime: " & GUICtrlRead($timeEndTime)) FileWriteLine($logFile, @TAB & "company: " & GUICtrlRead($comboCompanyName)) FileWriteLine($logFile, @TAB & "user: " & GUICtrlRead($comboUserName)) FileWriteLine($logFile, @TAB & "tasks completed: " & GUICtrlRead($textboxTasks)) FileClose($logFile) EndIf EndIf EndSwitch WEnd Func _NewUser() ; function for newuser form ; Global $formNewUser = GUICreate("redLabel timeKeeper", 275, 125) GUISetState() GUICtrlCreateLabel("new user", 25, 25) Global $inputNewUser = GUICtrlCreateInput("", 25, 47.5, 225) Local $buttonCancel = GUICtrlCreateButton("< &cancel", 100, 75, 75) Local $buttonCreate = GUICtrlCreateButton("&create >", 175, 75, 75) While 1 $msg = GUIGetMsg() Switch $msg Case $buttonCreate If GUICtrlRead($inputNewUser) == "" Then MsgBox(48, "redLabel timeKeeper", "a user must have a name!") Else $newUserMsgBox = MsgBox(36, "redLabel timeKeeper", "would you like to create this user?" & @CRLF & "'" & GUICtrlRead($inputNewUser) & "'") If $newUserMsgBox = 6 Then $varNewUser = GUICtrlRead($inputNewUser) FileWriteLine($users, $varNewUser & @CRLF) FIleClose($users) GUISwitch($mainForm) GUIDelete($formNewUser) Return EndIf EndIf Case $GUI_EVENT_CLOSE, $buttonCancel GUIDelete() GUISwitch($mainForm) Return EndSwitch WEnd EndFunc ;==>_NewUser Func _ViewLog() ; function for opening a log file ; Global $formViewLog = GUICreate("redLabel timeKeeper", 275, 150) GUISetState() Local $labelFormReq = GUICtrlCreateLabel("range must be one week interval, 'sun' to 'sat'.", 25, 25) GUICtrlCreateLabel("start date", 25, 50) Local $dtpStartDate = GUICtrlCreateDate("", 25, 72.5, 100) Local $currentDate = _NowCalcDate() Local $formatStartDate = GUICtrlGetHandle($dtpStartDate) _GUICtrlDTP_SetFormat($formatStartDate, 'yyyyMMdd') Local $weekStart = _DateAdd('D', -(@WDAY - 1), $currentDate) Local $displayStartDate = StringReplace($weekStart, "/", ' ') GUICtrlSetData($dtpStartDate, $displayStartDate) GUICtrlCreateLabel("end date", 150, 50) Local $dtpEndDate = GUICtrlCreateDate("", 150, 72.5, 100) Local $formatEndDate = GUICtrlGetHandle($dtpEndDate) _GUICtrlDTP_SetFormat($formatEndDate, 'yyyyMMdd') Local $weekEnd = _DateAdd('D', 7 - @WDAY, $currentDate) Local $displayEndDate = StringReplace($weekEnd, "/", ' ') GUICtrlSetData($dtpEndDate, $displayEndDate) Local $buttonCancel = GUICtrlCreateButton("< &cancel", 100, 100, 75) Local $buttonOpenLog = GUICtrlCreateButton("&open log >", 175, 100, 75) While 1 $msg = GUIGetMsg() Switch $msg Case $buttonOpenLog $varLogToOpen = $varDir & GUICtrlRead($dtpStartDate) & "." & GUICtrlRead($dtpEndDate) & ".txt" If Not FileExists($varLogToOpen) Then MsgBox(48, "redLabel timeKeeper", "please verify that dates range form 'sunday' to 'saturday'." & @CRLF & "logs are kept in one week intervals, 'sunday' to 'saturday'." & @CRLF & "only a vaild 'week' date range will be accepted." & @CRLF & "or logfile may have never existed.") Else ShellExecute($varLogToOpen) EndIf Case $GUI_EVENT_CLOSE, $buttonCancel GUIDelete() GUISwitch($mainForm) Return EndSwitch WEnd EndFunc ;==>_ViewLog Func _24Hour($time) ; function for converting am/pm time to 24hour for calculations ; Local $PM = False If StringInStr($time, 'PM') Then $PM = True $time = StringLeft($time, 5) $hour = Number(StringLeft($time, 2)) StringTrimRight($time, 2) $min = Number(StringRight($time, 2)) If Not $PM And $hour = 12 Then $hour = 0 If $PM And $hour < 12 Then $hour += 12 Return $hour & ':' & $min EndFunc ;==>_24Hour Func _OpenLogFile() ; function for writing to, or creating a new log file ; Local $logDir = "C:\ProgramData\tmPCSolutions\Weekly Logs\" Local $currentDate = _NowCalcDate() Local $weekStart = _DateAdd('D', -(@WDAY - 1), $currentDate) Local $weekEnd = _DateAdd('D', 7 - @WDAY, $currentDate) Local $fileName = StringReplace($weekStart & '.' & $weekEnd & ".txt", "/", '') If Not FileExists($logDir & "\" & $fileName) Then FileWrite($logDir & "\" & $fileName, "") EndIf Return FileOpen($logDir & "\" & $fileName, 1) EndFunc ;==>_OpenLogFile okay, i can't get my new user, and delete user functionality to work right. if you want run this see what is going on, you will need to have dir called C:\program files\tmPCSolutions\ 'this is where im running the script out of', and another dir called c:\ProgramData\tmPCSolutions\ ' this is where im keeping my Users.txt' with out it and with out some users in it, the script will not run. but when im try to create new users, and delete users from this file, i cannot get it to work. if you want to help out i would really appreciate it. or if you have any code refractoring ideas, i would appreciate that as well. thanks a lot in advanced. Edited April 3, 2010 by redLabel Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 3, 2010 Moderators Share Posted April 3, 2010 redLabel, This is how I would add/delete users using a combo and a file. Over to you to incorporate it into your script: expandcollapse popup#include <GUIConstantsEx.au3> #include <ComboConstants.au3> #Include <File.au3> ; Define file $sUserFile = @ScriptDir & "\Users.txt" ; Create GUI $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 150, 20, $CBS_DROPDOWNLIST) _Combo_Fill() $hAdd_Button = GUICtrlCreateButton("Add User", 10, 100, 80, 30) $hDel_Button = GUICtrlCreateButton("Del User", 10, 150, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hAdd_Button _Add_User() Case $hDel_Button _Del_User() EndSwitch WEnd Func _Add_User() Local $sNewUser = "" ; Get new user name Do $sNewUser = InputBox("Add User", "Add User Name", "") If @error = 1 Then Return Until $sNewUser <> "" ; Add user name to file FileWriteLine($sUserFile, $sNewUser) ; Fill Combo _Combo_Fill() EndFunc Func _Del_User() ; Read current selection $sDelUser = GUICtrlRead($hCombo) If $sDelUser <> "" Then ; Set line counter $iCount = 1 ; Look for that name in the file While 1 $sTemp = FileReadLine($sUserFile) If @error = -1 Then Return ; Exit the loop when found If $sTemp = $sDelUser Then ExitLoop ; Increase line count $iCount += 1 WEnd ; Delete the line with that user name _FileWriteToLine($sUserFile, $iCount, "", 1) ; Fill the combo _Combo_Fill() EndIf EndFunc Func _Combo_Fill() Local $aList ; Read the file _FileReadToArray($sUserFile, $aList) If Not @error Then ; Delete the current list GUICtrlSetData($hCombo, "|") ; Set the combo to the contents of the file For $i = 1 To $aList[0] GUICtrlSetData($hCombo, $aList[$i]) Next Else ; File empty, so delete current content GUICtrlSetData($hCombo, "|") EndIf EndFunc Come back if you run into problems. 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...
Necromorph Posted April 4, 2010 Author Share Posted April 4, 2010 thanks for you replies, the 'delete' button on your example doesn't do anything, and at the end of the 'new user' function, a @CRLF is need, else it will not add a new line. anyway. the combo fill function doesn't seem to work for me. it does write to the file, but not until after i close and reopen the program. thanks for you help though. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 4, 2010 Moderators Share Posted April 4, 2010 (edited) redLabel, The code above works for me - or I would not have posted it. The delete button requires you to select a name in the combo - how else does it know what to delete? Perhaps if you posted the code you have been trying which does not work, we might be able to see why you are having problems. M23 Edit: Clarity (I hope!) Edited April 4, 2010 by Melba23 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...
Necromorph Posted April 4, 2010 Author Share Posted April 4, 2010 yeah, i got it. thanks much, the only thing i want to change is a way to have it "default" to a 'none' user in the combobox when the gui is opened, but all the _GUICtrlComboBox_Func() i have been looking at will fail if you send it to a $CBS_DROPDOWNLIST. but i want to keep it uneditable, hence the need for a new/delete user button. just wondering if you have any ideas on that one. but the rest of it is working just fine. thanks a lot. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 4, 2010 Moderators Share Posted April 4, 2010 redLabel,Yes, it annoying that you cannot set a default text to a $CBS_DROPDOWNLIST combo. I tend to use a label in this case to make it clear that the combo is empty - like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ComboConstants.au3> #Include <File.au3> ; Define file $sUserFile = @ScriptDir & "\Users.txt" ; Create GUI $hGUI = GUICreate("Test", 500, 500) $hlabel_1 = GUICtrlCreateLabel("", 10, 10, 150, 20, $SS_BLACKFRAME) $hLabel_2 = GUICtrlCreateLabel("None", 12, 12, 146, 16) $hCombo = GUICtrlCreateCombo("", 10, 10, 150, 20, $CBS_DROPDOWNLIST) GUICtrlSetState(-1, $GUI_HIDE) _Combo_Fill() $hAdd_Button = GUICtrlCreateButton("Add User", 10, 100, 80, 30) $hDel_Button = GUICtrlCreateButton("Del User", 10, 150, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hAdd_Button _Add_User() Case $hDel_Button _Del_User() EndSwitch WEnd Func _Add_User() Local $sNewUser = "" ; Get new user name Do $sNewUser = InputBox("Add User", "Add User Name", "") If @error = 1 Then Return Until $sNewUser <> "" ; Add user name to file FileWriteLine($sUserFile, $sNewUser) ; Fill Combo _Combo_Fill() EndFunc Func _Del_User() ; Read current selection $sDelUser = GUICtrlRead($hCombo) If $sDelUser <> "" Then ; Set line counter $iCount = 1 ; Look for that name in the file While 1 $sTemp = FileReadLine($sUserFile) If @error = -1 Then Return ; Exit the loop when found If $sTemp = $sDelUser Then ExitLoop ; Increase line count $iCount += 1 WEnd ; Delete the line with that user name _FileWriteToLine($sUserFile, $iCount, "", 1) ; Fill the combo _Combo_Fill() EndIf EndFunc Func _Combo_Fill() Local $aList ; Read the file _FileReadToArray($sUserFile, $aList) If Not @error Then ; Hide labels and show combo GUICtrlSetState($hLabel_1, $GUI_HIDE) GUICtrlSetState($hLabel_2, $GUI_HIDE) GUICtrlSetState($hCombo, $GUI_SHOW) ; Delete the current list GUICtrlSetData($hCombo, "|") ; Set the combo to the contents of the file For $i = 1 To $aList[0] GUICtrlSetData($hCombo, $aList[$i]) Next Else ; File empty, so hide combo and show label GUICtrlSetState($hCombo, $GUI_HIDE) GUICtrlSetState($hLabel_1, $GUI_SHOW) GUICtrlSetState($hLabel_2, $GUI_SHOW) EndIf EndFuncIf you can come up with something better, please let me know! 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...
Necromorph Posted April 4, 2010 Author Share Posted April 4, 2010 (edited) okay, getting super close to a solution here. if you #include <GUIComboBox.au3> and using your first example. at the end of the _Combo_Fill() Function, add this,'$handleCombo = GUICtrlGetHandle($hCombo)' and this '_GUICtrlComboBox_SelectString($handleCombo, 'none')', it will work, it will make a 'default' for what string to be selected when the form is opened. but for some reason, the 'delete' button isn't working, so, everything but that is good. almost there! Edited April 4, 2010 by redLabel Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 redLabel,Using _GUICtrlComboBox_SelectString is a clever idea. The only inconvenience I can see is that it does require the combo to hold the value "None" - but that is minor.I have changed the file reading code to use a handle rather than the filename in case that was causing your problem - the "Delete" button works fine for me in this code.expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIComboBox.au3> #include <ComboConstants.au3> #Include <File.au3> ; Define file $sUserFile = @ScriptDir & "\Users.txt" ; Create GUI $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 150, 20, $CBS_DROPDOWNLIST) $hCombo_Handle = GUICtrlGetHandle($hCombo) _Combo_Fill() $hAdd_Button = GUICtrlCreateButton("Add User", 10, 100, 80, 30) $hDel_Button = GUICtrlCreateButton("Del User", 10, 150, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hAdd_Button _Add_User() Case $hDel_Button _Del_User() EndSwitch WEnd Func _Add_User() Local $sNewUser = "" ; Get new user name Do $sNewUser = InputBox("Add User", "Add User Name", "") If @error = 1 Then Return Until $sNewUser <> "" ; Add user name to file FileWriteLine($sUserFile, $sNewUser) ; Fill Combo _Combo_Fill() EndFunc Func _Del_User() ; Read current selection $sDelUser = GUICtrlRead($hCombo) If $sDelUser <> "" Then ; Set line counter $iCount = 1 ; Open file for reading $hFile = FileOpen($sUserFile) ; Look for that name in the file While 1 $sTemp = FileReadLine($hFile) If @error = -1 Then Return ; Exit the loop when found If $sTemp = $sDelUser Then ExitLoop ; Increase line count $iCount += 1 WEnd ; Close file so we can... FileClose($hFile) ; ...delete the line with that user name _FileWriteToLine($sUserFile, $iCount, "", 1) ; Fill the combo _Combo_Fill() EndIf EndFunc Func _Combo_Fill() Local $aList ; Read the file _FileReadToArray($sUserFile, $aList) If Not @error Then ; Delete the current list GUICtrlSetData($hCombo, "|") ; Set the combo to the contents of the file For $i = 1 To $aList[0] GUICtrlSetData($hCombo, $aList[$i]) Next Else ; File empty, so set None GUICtrlSetData($hCombo, "|None") _GUICtrlComboBox_SelectString($hCombo_Handle, 'None') EndIf EndFuncM23 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...
Necromorph Posted April 5, 2010 Author Share Posted April 5, 2010 (edited) thanks for all your help on this situation, i never thought that this sort of functionality would be so vexing, im going to try to wrap this program up some time today. thanks again! i did make a few changes though, if want to check them out expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIComboBox.au3> #include <ComboConstants.au3> #include <File.au3> #include <Array.au3> ; Define file $sUserFile = @ScriptDir & "\Users.txt" ; Create GUI $hGUI = GUICreate("Test", 500, 500) $hCombo = GUICtrlCreateCombo("", 10, 10, 150, 20, $CBS_DROPDOWNLIST) $hCombo_Handle = GUICtrlGetHandle($hCombo) _Combo_Fill() $hAdd_Button = GUICtrlCreateButton("Add User", 10, 100, 80, 30) $hDel_Button = GUICtrlCreateButton("Del User", 10, 150, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hAdd_Button _Add_User() Case $hDel_Button _Del_User() EndSwitch WEnd Func _Add_User() Local $sNewUser = "" ; Get new user name Do $sNewUser = InputBox("Add User", "Add User Name", "") If @error = 1 Then Return Until $sNewUser <> "" ; Add user name to file FileWriteLine($sUserFile, $sNewUser & @CRLF) ; Fill Combo _Combo_Fill() _GUICtrlComboBox_SelectString($hCombo_Handle, $sNewUser) EndFunc ;==>_Add_User Func _Del_User() ; Read current selection $sDelUser = GUICtrlRead($hCombo) If $sDelUser <> "" Then ; Set line counter $iCount = 1 ; Open file for reading $hFile = FileOpen($sUserFile) ; Look for that name in the file While 1 $sTemp = FileReadLine($hFile) If @error = -1 Then Return ; Exit the loop when found If $sTemp = $sDelUser Then ExitLoop ; Increase line count $iCount += 1 WEnd ; Close file so we can... FileClose($hFile) ; ...delete the line with that user name _FileWriteToLine($sUserFile, $iCount, "", 1) ; Fill the combo _Combo_Fill() EndIf EndFunc ;==>_Del_User Func _Combo_Fill() Local $aList ; Read the file _FileReadToArray($sUserFile, $aList) If Not @error Then ; Delete the current list GUICtrlSetData($hCombo, "|") ; Set the combo to the contents of the file For $i = 1 To $aList[0] _ArraySort($aList, 0, 2) GUICtrlSetData($hCombo, $aList[$i]) Next Else ; File empty, so set None GUICtrlSetData($hCombo, "|") EndIf _GUICtrlComboBox_SelectString($hCombo_Handle, 'none') EndFunc ;==>_Combo_Fill basically i have it _ArraySort() the array starting at index[2] so that the 'none' entry is always at the top, and not sorted alphabetically. and i added another _GUICtrlComboBox_SelectString() at the end of the _NewUser() function so that it will auto select the 'new user' in the combo box after you have created him. it is perfect ! thanks again! Edited April 5, 2010 by redLabel Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 5, 2010 Moderators Share Posted April 5, 2010 redLabel,i never thought that this sort of functionality would be so vexingWelcome to the wonderful world of programming! 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