Jump to content

Trying to make a attendance list for .CSV


Recommended Posts

Hi all!

Love Autoit, been trying to figure it for a while now but I am getting there. My script it not complete per say, as a side note. I am basically being lazy and using a GUI to log whenever I start my work, go for lunch, arrive from lunch and quit work for the day. I hope the script itself won't be too hard to look at I have tried clean the most off it (still got some more cleaning to do afterwards). 

#include <ParseCSV.au3>
#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $sFile = @ScriptDir & "\Närvaro.csv"
Local $sDelimiters = ";"
Global $here = _parseCSV ($sFile, $sDelimiters)
Global $i, $l
Global $sDate = @YEAR & "-" & @MON & "-" & @MDAY
Global $hh = "hh"
Global $mm = "mm"
Global $time = 0
Global $lengh = UBound($here)

;~ _ArrayDisplay($here)
;~ MsgBox(1,"",$time)
;~ Exit

Func InsertTime($collumn,$Title,$content)
;~    $lengh = UBound($here) - 1
;~    MsgBox(1,"",$collumn & " " & $lengh)
   If $time == 0 Then
 $here[$lengh][$collumn] = @HOUR & ":" & @MIN
   Else
 $here[$lengh][$collumn] = $time
   EndIf
   _FileWriteFromArray($sFile,$here,Default,Default,";")
   MsgBox(0,$Title, $content)
EndFunc

Func setDate()
   For $i = 1 To UBound($here) -1
 If $here[$i][0] = $sDate Then
;~ MsgBox(0,"",$i & " " & $sDate)
 Else
_ArrayAdd($here, $sDate, 0)
 EndIf
 $lengh = $i
   Next
EndFunc

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 338, 148, 391, 301)
$arrive = GUICtrlCreateButton("Anländer", 0, 0, 75, 25, $WS_GROUP)
$lunch_s = GUICtrlCreateButton("Lunch Börjar", 80, 0, 75, 25, $WS_GROUP)
$lunch_e = GUICtrlCreateButton("Lunch Slut", 160, 0, 75, 25, $WS_GROUP)
$end = GUICtrlCreateButton("Avgår", 240, 0, 75, 25, $WS_GROUP)
$manual_time = GUICtrlCreateCheckbox("Skriv in manuell tid", 16, 32, 161, 17)
$date = GUICtrlCreateDate(@YEAR & "/" & @MON & "/" & @MDAY, 16, 104, 226, 21, $WS_TABSTOP)
$type = GUICtrlCreateLabel("Skriv in tiden manuellt:", 16, 56, 110, 17)
$close = GUICtrlCreateButton("Stäng", 272, 80, 59, 49, $WS_GROUP)
$hours = GUICtrlCreateInput($hh, 128, 56, 25, 21)
GUICtrlSetLimit(-1, 2)
$collon = GUICtrlCreateLabel(":", 160, 56, 7, 17)
$minutes = GUICtrlCreateInput($mm, 168, 56, 25, 21)
$save = GUICtrlCreateButton("Spara", 200, 56, 43, 25, $WS_GROUP)
$array = GUICtrlCreateButton("Visa" & @LF & "tabell", 272, 40, 40, 33, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

SetDate()
_ArrayAdd($here, $sDate, 0)

;~ MsgBox(1,"",$lengh)
;~ _ArrayDisplay($here)
;~ Exit

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $arrive
   InsertTime(1,"Welcome!","Welcome back master, have a productive day!" & @LF & "-Minions")
Case $lunch_s
   InsertTime(2,"Lunch!","Off to eat? Most important meal of the day, we have prepared the ritual for you!" & @LF & "-Minions")
Case $lunch_e
   InsertTime(3,"Back from lunch!","I hope the lambs and goats was to your liking, we made sure they were extra innocent!" & @LF & "-Minions")
Case $end
;~    If @WDAY == 5 Then
 InsertTime(4,"End!","Farewell master, see you in the morning!" & @LF & "-Minions")
;~    ElseIf @WDAY >= 6 Then
;~    InsertTime(4,"End!","Working on a weekday? Shame on you!" & @LF & "-Minions")
;~    Else
;~  InsertTime(4,"End!","Farewell master, see you in the morning!" & @LF & "-Minions")
;~    EndIf

Case $manual_time
Case $date
   $sDate = GUICtrlRead($date)
   SetDate()

Case $array
   _ArrayDisplay($here)
Case $close
   Exit
EndSwitch
WEnd

 

Basically one of the primal functions to "setDate()" is to compare today's date OR the date set if user changes it using the GUI. However it does not seem to work! when I execute the script, and I push button to log a time it all works fine and dandy even if I restart the script, and that's what I want! But I just can't get my head wrapped around why it is adding today's date a second time. Not a third or fourth mind you, only once!.. Maybe I got something wrong with setting up the date.. that is also a thing I haven't got to right now. The GUI got the option of selecting a date it will work by, can it be that that's messing with me?
Edited by Sodori
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...