AutID Posted August 19, 2013 Share Posted August 19, 2013 (edited) Hello, I am trying to make a program which will show me the time, date etc of the employs in my work and will write down the informations in a file. I tried to make a reproducer expandcollapse popup#include <GUIConstantsEx.au3> #include <File.au3> #include "Config.au3" $hGUI = GUICreate("Horaires du personnel", 400, 200) $clocklabel = GUICtrlCreateLabel(@HOUR & ":" & @MIN & ":" & @SEC, 350,100) $datelabel = GUICtrlCreateLabel(@MDAY & "/" & @MON & "/" & @YEAR, 335,130) $prenomlabel = GUICtrlCreateLabel("Prenom: ", 10, 30, 150) $heureslabel = GUICtrlCreateLabel("Heures: ", 10, 50, 150) $jourslabel = GUICtrlCreateLabel("Jours: ", 10, 70, 150) $label = GUICtrlCreateLabel("", 10, 100,200, 25) $arreterbutton = GUICtrlCreateButton("Arreter", 10, 170, 50) $sauvegarder GUICtrlCreateButton("Sauvegarder", 70,170, 70) $input = GUICtrlCreateInput("", 150, 170, 30, 23) $List = GUICtrlCreateCombo("", 190, 170, 200, 25) GUICtrlSetData(-1, "Kelly|Babis|Lorenco|Adrien|Ben|Marwan|Tony|Roko|Fotis|Adrea") GUISetState(@SW_SHOW) While (True) While @SEC GUICtrlSetData($clocklabel, @HOUR & ":" & @MIN & ":" & @SEC) Sleep(100) ExitLoop WEnd $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $arreterbutton GUICtrlSetData($heureslabel, "Heures: " & _Arreter()) GUICtrlSetData($jourslabel, "Jours: " & _DateDayOfWeek(@WDAY)) GUICtrlSetData($prenomlabel, "Prenom: " & GUICtrlRead($List)) IniWrite($profilFile, GUICtrlRead($List), "Heures", _Arreter()) IniWrite($profilFile, GUICtrlRead($List), "Jours", _DateDayOfWeek(@WDAY)) Case $sauvegarder _FileCreate($path) ;writeConfig() EndSwitch WEnd Func _Arreter() Local $newhour Local $hour = GUICtrlRead($input) $newhour = @HOUR - $hour Return $newhour EndFunc $arreterbutton sets the hours and the day of the person given in the $List and write them in the ini file.Is there a way to make $sauvegarder button to write down the day and hours of all people in once without having to write IniWrite 20 times in the script???I am not good with For/Next loops :/Edit: Config.au3 attachedConfig.au3 Edited August 19, 2013 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
FireFox Posted August 19, 2013 Share Posted August 19, 2013 Hi,Take a look at the IniRead/WriteSection.You should rearrange your ini, e.g: make a "Heures" and "Jour" sections with the staff in it instead of sections with the names of them.Br, FireFox. Link to comment Share on other sites More sharing options...
FireFox Posted August 19, 2013 Share Posted August 19, 2013 Another thing: Your nested while is useless (because always true), do this instead:... Local $hTimerSec = TimerInit() ... While (True) Sleep(10) If TimerDiff($hTimerSec) >= 1000 Then $hTimerSec = TimerInit() GUICtrlSetData($clocklabel, @HOUR & ":" & @MIN & ":" & @SEC) EndIf ... Link to comment Share on other sites More sharing options...
AutID Posted August 19, 2013 Author Share Posted August 19, 2013 (edited) I can't make only 2 sections with hours and days because everyone stops on different times and days.This is my current function. Local $hTimerSec = TimerInit() While (True) Sleep(10) If TimerDiff($hTimerSec) >= 1000 Then $hTimerSec = TimerInit() GUICtrlSetData($clocklabel, @HOUR & ":" & @MIN & ":" & @SEC) EndIf $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE $msgbox = MsgBox(3, "Attention", "Attention le fichier des informations sera supprimé. Voulez-vous enregistrer les informations de la journée?") If $msgbox = 6 Then $File = _FileCreate($path) $read = FileRead($profilFile) $write = FileWrite($path, $read) ElseIf $msgbox = 7 Then FileDelete(@ScriptDir & "\settings.ini") Exit ElseIf $msgbox = 2 Then EndIf Case $arreterbutton GUICtrlSetData($heureslabel, "Heures: " & _Arreter()) GUICtrlSetData($jourslabel, "Jours: " & _DateDayOfWeek(@WDAY)) GUICtrlSetData($prenomlabel, "Prenom: " & GUICtrlRead($List)) IniWrite($profilFile, GUICtrlRead($List), _Arreter(), "Heures") IniWrite($profilFile, GUICtrlRead($List), _DateDayOfWeek(@WDAY), "Jour") Case $sauvegarder $File = _FileCreate($path) $read = FileRead($profilFile) $write = FileWrite($path, $read) EndSwitch WEndWhen I press $sauvegarder button it reads the .ini file, copy it and write it in the new file. What I want to do is, to write the day in the Day data and the phrase "jusqu'à la fin" in the hours data for every employ that didn't finished earlier.E.g. This is the .ini file when only one has finished earlier.[Kelly]4=HeuresMonday=Jour[babis][Lorenco][Adrien][ben][Marwan][Tony][Roko][Fotis][Adrea]Is it possible to write for every other person who didn't finished earlier the Day and the phrase "jusqu'a la fin"?? Like this:[babis]Jusqu'a la fin=HeuresMonday=Jouretc...Edit: Attached the new Config.au3 file. Changed to IniWriteSectionConfig.au3 Edited August 19, 2013 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
FireFox Posted August 19, 2013 Share Posted August 19, 2013 Use a XML file or write multi data in one key.[Kelly] Heures=4 Jour=Monday [Babis] Heures=2 Jour=TuesdayBecomes:[Staff] Names=Kelly;Babis Heures=4;2 Jour=Monday;TuesdayBr, FireFox. Link to comment Share on other sites More sharing options...
Solution AutID Posted August 20, 2013 Author Solution Share Posted August 20, 2013 (edited) Use a XML file or write multi data in one key.[Kelly] Heures=4 Jour=Monday [Babis] Heures=2 Jour=TuesdayBecomes:[Staff] Names=Kelly;Babis Heures=4;2 Jour=Monday;TuesdayBr, FireFox.Why go so far? Besides, I like a lot ini functions. And the can combine with file functions Anyway found the solution;) This is what I came up with... Case $sauvegarder Local $names = IniReadSectionNames($profilFile) For $i = 1 To $names[0] Local $section = IniReadSection($profilFile, $names[$i]) If @error Then IniWrite($profilFile, $names[$i], "Service complet", "Vrai") IniWrite($profilFile, $names[$i], "Jour", _DateDayOfWeek(@WDAY)) Else For $t = 1 To $section[0][0] ConsoleWrite($section[$t][0] & $section[$t][1] & @CRLF) Next EndIf Next $File = _FileCreate($path) $read = FileRead($profilFile) $write = FileWrite($path, $read) EndSwitch WEnd ... Edited August 20, 2013 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
FireFox Posted August 20, 2013 Share Posted August 20, 2013 (edited) Why go so far?It's not a good way to store data.When you make a database you don't create a table for each staff member and in these tables their informations but instead a table named staff with the members and their informations.Br, FireFox. Edited August 20, 2013 by FireFox 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