JackCaldwell Posted February 28, 2019 Share Posted February 28, 2019 Hi all, I am new to AutoIT and I'm looking to make a script that runs at startup that will take the current time and place it in a notepad file in a set location. It will then need to count a set amount of time and relog another time 7 and a half hours later. This is used for when i come into work, it will log the time i log in and when I'm about to leave. It will also need to consider any time the laptop is turned off, it will need to resume with the same day and notepad file instead of starting another, Then a fresh one for the next day, if that makes any sense. Didn't know if anyone could point me in the right direction on where to start. I only know some very basic AutoIT and not even fluent in what I know. Any help would be greatly appreciated Link to comment Share on other sites More sharing options...
Earthshine Posted February 28, 2019 Share Posted February 28, 2019 start with the _Timer functions in the help file. As a rule, the help files is where you start when you are new. JackCaldwell 1 My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
abberration Posted February 28, 2019 Share Posted February 28, 2019 (edited) Dude, I'm working on a timeclock to post in the examples section. It's not finished yet, but here's the code if you want to take a look at it. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <ColorConstants.au3> #include <Array.au3> #include <String.au3> $filTimeData = "TimeclockData.ini" $filSettings = "TimeclockSettings.ini" $varTimeFormat = "ampm" $varCurrentTime = _FormatTime(@HOUR & ":" & @MIN) Local $varName $guiMain = GUICreate("Timeclock", 348, 134) ;$varColor = "$COLOR_" & IniRead($filSettings, "ColorScheme", "Color", "WHITE") ;MsgBox(0, "", $varColor) ;Assign("varColor", "$COLOR_" & IniRead($filSettings, "ColorScheme", "Color", "WHITE")) ;GUISetBkColor($varColor) $guiDate = GUICtrlCreateDate("", 16, 8, 82, 21, $WS_TABSTOP) $guiLabel = GUICtrlCreateLabel($varCurrentTime, 114, 8, 50, 17) $guiCombo = GUICtrlCreateCombo("", 176, 8, 154, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL,$WS_VSCROLL)) $guiButton1 = GUICtrlCreateButton("Clock In", 16, 40, 75, 23, $WS_GROUP) $guiButton2 = GUICtrlCreateButton("Begin Lunch", 96, 40, 75, 23, $WS_GROUP) $guiButton3 = GUICtrlCreateButton("Lunch Over", 176, 40, 75, 23, $WS_GROUP) $guiButton4 = GUICtrlCreateButton("Go Home", 256, 40, 75, 23, $WS_GROUP) $guiButton5 = GUICtrlCreateButton("Refresh Time", 16, 80, 75, 23, $WS_GROUP) $guiButton6 = GUICtrlCreateButton("Edit Data", 256, 80, 75, 23, $WS_GROUP) $guiMenuFile = GUICtrlCreateMenu("File") $guiMenuReport = GUICtrlCreateMenuItem("Generate Report", $guiMenuFile) $guiMenuExit = GUICtrlCreateMenuItem("Exit", $guiMenuFile) $guiMenuSettings = GUICtrlCreateMenu("Settings") $guiMenuAddUser = GUICtrlCreateMenuItem("Add User", $guiMenuSettings) $guiMenuDelUser = GUICtrlCreateMenuItem("Delete User", $guiMenuSettings) $guiMenuProgSettings = GUICtrlCreateMenuItem("Program Settings", $guiMenuSettings) $guiMenuAbout = GUICtrlCreateMenu("About") $guiMenuAboutTC = GUICtrlCreateMenuItem("About Trimeclock", $guiMenuAbout) GUISetState(@SW_SHOW) If NOT FileExists($filTimeData) Then _AddName() _PopulateCombo($vatrName) Else _PopulateCombo("NoName") EndIf _DisableButtons() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $guiMenuAddUser $varName = _AddName() If $varName <> "" Then _PopulateCombo($varName) EndIf Case $guiMenuDelUser _DeleteUsers() Case $guiButton1 $varDate = _DateConvert(GUICtrlRead($guiDate)) $varCurrentUser = GUICtrlRead($guiCombo) $varTime = _ReadTime() IniWrite($filTimeData, $varCurrentUser, $varDate & "a", $varTime) _DisableButtons() Case $guiButton2 $varDate = _DateConvert(GUICtrlRead($guiDate)) $varCurrentUser = GUICtrlRead($guiCombo) $varTime = _ReadTime() IniWrite($filTimeData, $varCurrentUser, $varDate & "b", $varTime) _DisableButtons() Case $guiButton3 $varDate = _DateConvert(GUICtrlRead($guiDate)) $varCurrentUser = GUICtrlRead($guiCombo) $varTime = _ReadTime() IniWrite($filTimeData, $varCurrentUser, $varDate & "c", $varTime) _DisableButtons() Case $guiButton4 $varDate = _DateConvert(GUICtrlRead($guiDate)) $varCurrentUser = GUICtrlRead($guiCombo) $varTime = _ReadTime() IniWrite($filTimeData, $varCurrentUser, $varDate & "d", $varTime) _DisableButtons() Case $guiCombo _EnableButtons() _DisableButtons() Case $guiDate _EnableButtons() _DisableButtons() EndSwitch WEnd Func _PopulateCombo($varName) GUICtrlSetData($guiCombo, "") $arrNames = IniReadSectionNames($filTimeData) $strNames = StringTrimLeft(_ArrayToString($arrNames, "|"), 2) If $varName = "NoName" Then $varName = $arrNames[1] EndIf GUICtrlSetData($guiCombo, $strNames, $varName) EndFunc Func _AddName() $varName = Inputbox("Enter A Name", "Please enter a name to add to the timeclock:") If $varName <> "" Then IniWriteSection($filTimeData, $varName, "") EndIf Return($varName) EndFunc Func _DisableButtons() $varCurrentUser = GUICtrlRead($guiCombo) $varDate = _DateConvert(GUICtrlRead($guiDate)) $varTime1 = _FormatTime(IniRead($filTimeData, $varCurrentUser, $varDate & "a", "null")) $varTime2 = _FormatTime(IniRead($filTimeData, $varCurrentUser, $varDate & "b", "null")) $varTime3 = _FormatTime(IniRead($filTimeData, $varCurrentUser, $varDate & "c", "null")) $varTime4 = _FormatTime(IniRead($filTimeData, $varCurrentUser, $varDate & "d", "null")) If $varTime1 <> "null" Then GUICtrlSetState ($guiButton1, $Gui_Disable) GUICtrlSetData($guiButton1, $varTime1) EndIf If $varTime2 <> "null" Then GUICtrlSetState ($guiButton2, $Gui_Disable) GUICtrlSetData($guiButton2, $varTime2) EndIf If $varTime3 <> "null" Then GUICtrlSetState ($guiButton3, $Gui_Disable) GUICtrlSetData($guiButton3, $varTime3) EndIf If $varTime4 <> "null" Then GUICtrlSetState ($guiButton4, $Gui_Disable) GUICtrlSetData($guiButton4, $varTime4) EndIf EndFunc Func _EnableButtons() GUICtrlSetState ($guiButton1, $Gui_Enable) GUICtrlSetState ($guiButton2, $Gui_Enable) GUICtrlSetState ($guiButton3, $Gui_Enable) GUICtrlSetState ($guiButton4, $Gui_Enable) GUICtrlSetData($guiButton1, "Clock In") GUICtrlSetData($guiButton2, "Begin Lunch") GUICtrlSetData($guiButton3, "Lunch Over") GUICtrlSetData($guiButton4, "Go Home") EndFunc Func _DateConvert($varDate) $arrDate = StringSplit($varDate, "/", 2) $varDate = StringFormat("%02d", $arrDate[2]) & StringFormat("%02d", $arrDate[0]) & StringFormat("%02d",$arrDate[1]) Return $varDate EndFunc Func _DeleteUsers() $guiDelUserForm = GUICreate("Delete User", 220, 200) $guiListview = GUICtrlCreateListView("Name|", 10, 10, 200, 150, $WS_BORDER, $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES) _GUICtrlListView_SetColumnWidth($guiListView,0,180) $guiButton7 = GUICtrlCreateButton("Delete", 75, 170, 70, 20) GUISetState(@SW_SHOW) $arrNames = IniReadSectionNames($filTimeData) For $i = 1 To $arrNames[0] GUICtrlCreateListViewItem($arrNames[$i], $guiListview) Next While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($guiDelUserForm) ExitLoop Case $guiButton7 $varConfirm = MsgBox(49, "Caution", "Are you sure you want to delete selected userss?" & @crlf & "Deleting users will also delete the timeclock data associated with them.") If $varConfirm = 1 Then $varItemCount = _GUICtrlListView_GetItemCount ( $guiListView ) For $i = 1 To $varItemCount If _GUICtrlListView_GetItemChecked($guiListview, $i - 1) = "True" Then $varName = _GUICtrlListView_GetItemTextString ($guiListview, $i - 1) IniDelete($filTimeData, $varName) EndIf Next EndIf _PopulateCombo("NoName") _EnableButtons() _DisableButtons() GUIDelete($guiDelUserForm) ExitLoop EndSwitch WEnd EndFunc Func _ReadTime() $varTime = GUICtrlRead($GuiLabel) If StringRight($varTime, 2) = "am" OR StringRight($varTime, 2) = "pm" Then If StringRight($varTime, 2) = "pm" Then $varHour = StringLeft($varTime, 2) + 12 Else $varHour = StringLeft($varTime, 2) EndIf $varMin = StringMid($varTime, 3, 2) Else $varHour = StringLeft($varTime, 2) $varMin = StringMid($varTime, 3, 2) EndIf $varTime = $varHour & ":" & $varMin Return $varTime EndFunc Func _FormatTime($varTime) If $varTime <> "null" Then $varHour = StringLeft($varTime, 2) $varMin = StringRight($varTime, 2) If $varTimeFormat = "ampm" Then If $varHour < 13 Then $varCurrentTime = $varHour & ":" & $varMin & " am" Else $varCurrentTime = $varHour - 12 & ":" & $varMin & " pm" EndIf Else $varCurrentTime = $varHour & ":" & $varMin EndIf Else $varCurrentTime = "null" EndIf Return $varCurrentTime EndFunc Edited March 1, 2019 by abberration added variable declaration to fix script breaking JackCaldwell 1 Easy MP3 | Software Installer | Password Manager 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