Jump to content

IniWrite on multiple vars


AutID
 Share

Go to solution Solved by AutID,

Recommended Posts

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

 

#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 attached

Config.au3

Edited by AutID
Link to comment
Share on other sites

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

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
WEnd
When 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=Heures

Monday=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=Heures

Monday=Jour

etc...

Edit: Attached the new Config.au3 file. Changed to IniWriteSection

Config.au3

Edited by AutID
Link to comment
Share on other sites

  • Solution

Use a XML file or write multi data in one key.

[Kelly]
Heures=4
Jour=Monday
[Babis]
Heures=2
Jour=Tuesday
Becomes:

[Staff]
Names=Kelly;Babis
Heures=4;2
Jour=Monday;Tuesday
Br, 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 by AutID
Link to comment
Share on other sites

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 by FireFox
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...