Jump to content
Sign in to follow this  
r3dbullo88

Any improvements for this Room-Booking script?

Recommended Posts

r3dbullo88

Ehi Guys, I've edited this post according to the big last update on this work.

//

This script handles the booking system of a room.

The room is composed of 3 seats, which can be booked between 3 different time zones 07:00-09:00, 12:00-14:00 and 18:00-20:00.

The function that can be used are:

- Prenota ( Insert a Booking )
- Verifica disponibilità ( Display booking of given date / time zone)
- Cancella prenotazione ( Delete a booking, using a passcode that is generated while creating the Booking )
- Le mie prenotazioni ( Display the bookings of the current user on given date )

The script is fully working, initially based on an Excel file and lately switched to SQLite which I feel more stable for this.

What I am looking for here: I am looking on ways to improve the code

Thanks in advance for any support,

Luciano.

Below, the last version:

#include <Array.au3>
#include <Date.au3>
#include <SQLite.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <GuiComboBox.au3>

Global $lista_orari[31]=["Seleziona Orario","07:00 - 07:30","07:00 - 08:00","07:00 - 08:30","07:00 - 09:00","07:30 - 08:00","07:30 - 08:30","07:30 - 09:00","08:00 - 08:30","08:00 - 09:00","08:30 - 09:00","12:00 - 12:30","12:00 - 13:00","12:00 - 13:30","12:00 - 14:00","12:30 - 13:00","12:30 - 13:30","12:30 - 14:00","13:00 - 13:30","13:00 - 14:00","13:30 - 14:00","18:00 - 18:30","18:00 - 19:00","18:00 - 19:30","18:00 - 20:00","18:30 - 19:00","18:30 - 19:30","18:30 - 20:00","19:00 - 19:30","19:00 - 20:00","19:30 - 20:00"]
Global $lista_posti[4]=["Seleziona Posto","Poltrona","Cuscino A","Cuscino B"]
Global $fascia_orari[4]=["Seleziona Fascia","Mattina","Pranzo","Sera"]
Global $aPrenotazione,$posto_prenotazione,$pass_prenotazione,$aResult
Global $DB="K:\Public Folder\Italy IT\Relax Room\testDB.db"

;Main GUI
#Region ### START Koda GUI section ### Form=H:\AutoIT Scripts\Relax Room\Booking_Tool_Main.kxf
$GUI_Main = GUICreate("Relax Room Booking Tool", 882, 451, 324, 354)
GUISetBkColor(0x000000)
$Console = GUICtrlCreateEdit("", 416, 8, 449, 425, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetData($Console,"Relax Room Booking Tool Console"&@crlf)
$Button_Prenota = GUICtrlCreateButton("Prenota", 16, 80, 385, 81)
$Button_Check = GUICtrlCreateButton("Verifica Disponibilità", 16, 184, 385, 81)
$Button_Delete = GUICtrlCreateButton("Cancella Prenotazione", 16, 288, 385, 81)
$Button_Exit = GUICtrlCreateButton("Esci", 304, 384, 97, 49)
$Button_MyBook = GUICtrlCreateButton("Le mie prenotazioni", 144, 384, 145, 49)
GUICtrlCreateLabel("Relax Room Booking Tool", 56, 24, 303, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
$Biogen_Logo = GUICtrlCreatePic("K:\Public Folder\Italy IT\Relax Room\Aratari_Logo.jpg", 18, 394, 105, 41)
GUISetState(@SW_SHOW,$GUI_Main)
#EndRegion ### END Koda GUI section ###

;Prenota GUI
#Region ### START Koda GUI section ### Form=H:\AutoIT Scripts\Relax Room\GUI_Prenota.kxf
$GUI_Prenota = GUICreate("Relax Room - Prenota", 351, 316, 1236, 354)
GUISetBkColor(0x000000)
$Date1 = GUICtrlCreateDate(_NowCalc ( ), 152, 16, 185, 49,$DTS_SHORTDATEFORMAT)
$Combo1 = GUICtrlCreateCombo("", 152, 96, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("Data", 16, 24, 59, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("Orario", 16, 88, 80, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("Posto", 16, 160, 70, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
$Combo2 = GUICtrlCreateCombo("", 152, 168, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
For $i=1 To Ubound($lista_orari)-1
    GUICtrlSetData($Combo1,$lista_orari[$i])
 Next
For $i=1 To Ubound($lista_posti)-1
    GUICtrlSetData($Combo2,$lista_posti[$i])
Next
$Button_Conferma_Prenotazione = GUICtrlCreateButton("Prenota", 32, 232, 113, 57)
$Button_Annulla_Prenotazione = GUICtrlCreateButton("Annulla", 208, 232, 113, 57)
GUISetState(@SW_HIDE,$GUI_Prenota)
#EndRegion ### END Koda GUI section ###

;Check GUI 2.0
#Region ### START Koda GUI section ### Form=h:\autoit scripts\relax room\gui_check.kxf
$GUI_Check = GUICreate("Relax Room - Verifica disponibilità", 724, 284, 369, 473)
GUISetBkColor(0x000000)
$Date_Check = GUICtrlCreateDate(_NowCalc ( ), 152, 40, 185, 49,$DTS_SHORTDATEFORMAT)
$Combo_Check = GUICtrlCreateCombo("", 184, 120, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
For $i=1 To Ubound($fascia_orari)-1
    GUICtrlSetData($Combo_Check,$fascia_orari[$i])
Next
GUICtrlCreateLabel("Data", 16, 48, 59, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("Fascia Oraria", 16, 112, 156, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
$Button_Check_Verifica = GUICtrlCreateButton("Verifica", 32, 200, 113, 57)
$Button_Check_Annulla = GUICtrlCreateButton("Annulla", 192, 200, 113, 57)
$Edit_Check = GUICtrlCreateEdit("", 352, 8, 361, 257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "Inserisci la data e la fascia oraria poi clicca su Verifica.")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

;MyBook GUI
#Region ### START Koda GUI section ### Form=h:\autoit scripts\relax room\gui_prenota.kxf
$GUI_MyBook = GUICreate("Relax Room - Le mie prenotazioni", 668, 163, 520, 521)
GUISetBkColor(0x000000)
$Date_MyBook = GUICtrlCreateDate(_NowCalc ( ), 80, 16, 193, 49,$DTS_SHORTDATEFORMAT)
GUICtrlCreateLabel("Data", 16, 24, 59, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
$Button_MyBook_Verifica = GUICtrlCreateButton("Verifica", 16, 88, 113, 57)
$Button_MyBook_Annulla = GUICtrlCreateButton("Annulla", 160, 88, 113, 57)
$Edit_MyBook = GUICtrlCreateEdit("Seleziona la data e premi Verifica", 288, 8, 369, 145, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "Seleziona la data e premi Verifica")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

;Delete GUI
#Region ### START Koda GUI section ### Form=h:\autoit scripts\relax room\gui_check.kxf
$GUI_Delete = GUICreate("Relax Room - Cancella prenotazione", 444, 186, 462, 482)
GUISetBkColor(0x000000)
GUICtrlCreateLabel("Codice Prenotazione", 8, 56, 241, 37)
GUICtrlSetFont(-1, 22, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
$Button_Delete_Conferma = GUICtrlCreateButton("Conferma", 72, 120, 113, 57)
$Button_Delete_Annulla = GUICtrlCreateButton("Annulla", 264, 120, 113, 57)
GUICtrlCreateLabel("Inserisci il codice della prenotazione che desideri eliminare e poi premi su Conferma", 24, 8, 393, 17)
GUICtrlSetFont(-1, 9, 400, 0, "Californian FB")
GUICtrlSetColor(-1, 0xFF0000)
$pass_delete = GUICtrlCreateInput("", 264, 56, 177, 37)
GUICtrlSetLimit(-1, 6)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

Func WriteDB($aPrenotazione)
   Local $aResult, $iRows, $iColumns, $iRval
   _SQLite_Startup("sqlite3.dll")
   If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   Local $hDB = _SQLite_Open($DB)    ; for a memory DB or _SQLite_Open("myDB.sq3") for a disk-based DB
   If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   ;-- If we do a Fresh Startup, with an Empty DB, we need to create it:
   ;First startup, need to create DB
   ;If Not _SQLite_Exec(-1, "CREATE TABLE Booking (data_prenotazione,fascia_prenotazione,cod_ora_prenotazione,ora_prenotazione,posto_prenotazione,username,pass_prenotazione);") = $SQLITE_OK Then _
   ;MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())

   If Not _SQLite_Exec(-1, "INSERT INTO Booking VALUES ("&$aPrenotazione&");") = $SQLITE_OK Then
      If _SQLite_ErrMsg()="database is locked" Then
         MsgBox(64,"Database bloccato","Il database è in uso da un'altro utente, riprovare più tardi.",5)
      EndIf
   Else
      _GUICtrlEdit_AppendText($Console,"Prenotazione inserita con successo, prendi nota del codice di prenotazione: "&$pass_prenotazione&@crlf)
      MsgBox(64,"Prenotazione OK!","Il codice della tua prenotazione è: "&$pass_prenotazione,10)
   EndIf
  _SQLite_Close()
  _SQLite_Shutdown()
EndFunc

Func ReadDB()
   Local $iRows, $iColumns, $iRval
   _SQLite_Startup("sqlite3.dll")
   If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   Local $hDB = _SQLite_Open($DB)
   If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   If _SQLite_ErrMsg()="database is locked" Then
      MsgBox(64,"Database bloccato","Il database è in uso da un'altro utente, riprovare più tardi.",5)
   EndIf
   $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Booking WHERE data_prenotazione = '"&$data_prenotazione&"' AND fascia_prenotazione='"&$fascia_prenotazione&"';", $aResult, $iRows, $iColumns)
   _SQLite_Close()
   _SQLite_Shutdown()
EndFunc

Func CheckDB()
   Local $data = GUICtrlRead($Date_Check)
   Local $fascia = GUICtrlRead($Combo_Check)
   Local $iRows, $iColumns, $iRval
   _SQLite_Startup("sqlite3.dll")
   If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   Local $hDB = _SQLite_Open($DB)    ; for a memory DB or _SQLite_Open("myDB.sq3") for a disk-based DB
   If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   If _SQLite_ErrMsg()="database is locked" Then
      MsgBox(64,"Database bloccato","Il database è in uso da un'altro utente, riprovare più tardi.",5)
   EndIf
   $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Booking WHERE data_prenotazione = '"&$data&"' AND fascia_prenotazione = '"&$fascia&"';", $aResult, $iRows, $iColumns)
   _SQLite_Close()
   _SQLite_Shutdown()
   If $iRval = $SQLITE_OK Then
      Local $text_display
      For $i = 1 to Ubound($aResult)-1
         $text_display &=@crlf & " - - - " & @crlf & $aResult[$i][3] & " - " & $aResult[$i][4] & " - " & $aResult[$i][5]
      Next
      If $text_display = "" Then
         GUICtrlSetData($Edit_Check,"Non ci sono prenotazioni nella data selezionata ( "&$data&" ).")
      Else
         GUICtrlSetData($Edit_Check,"Le prenotazioni per la data e fascia oraria selezionata"&@crlf&"( "&$data&" - "&$fascia&" ):"&@crlf&$text_display)
      EndIf
    Else
       MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
   EndIf
EndFunc

Func CheckIfRoomIsFree($fascia_prenotazione,$posto_prenotazione)
   Local $room_status=0 ; 0=libera, 1,2,3,4,5,... = Mostra l'orario in cui la stanza è occupata e in conflitto con l'orario che desideriamo prenotare
   For $i = 1 To UBound($aResult,1)-1
      If $aResult[$i][4] = $posto_prenotazione Then ; Se si tratta dello stesso posto:
         If $aResult[$i][1] = $fascia_prenotazione Then ; Se si tratta della stessa fascia oraria
            ;Allora controllo l'orario
            ConsoleWrite(" - - START - - "&@crlf)
            ConsoleWrite($aResult[$i][0] & " <- Booked | Trying to Book-> " & $data_prenotazione&@crlf)
            ConsoleWrite($aResult[$i][4] & " <- Booked | Trying to Book-> " & $posto_prenotazione&@crlf)
            ConsoleWrite($aResult[$i][1] & " <- Booked | Trying to Book-> " & $fascia_prenotazione&@crlf)
            ConsoleWrite($aResult[$i][2] & " <- Booked | Trying to Book-> " & $cod_ora_prenotazione&@crlf)
            ConsoleWrite($aResult[$i][3] & " <- Booked | Trying to Book-> " & $lista_orari[$cod_ora_prenotazione]&@crlf)
            ConsoleWrite(" - - FINISH - - "&@crlf)
            Local $right_cod_ora = StringRight($cod_ora_prenotazione,1)
            Switch StringRight($aResult[$i][2],1)
            Case 1
               If $right_cod_ora <= 4 AND $right_cod_ora >= 1 Then
                  $room_status=1 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 1
                  ExitLoop
               EndIf
            Case 2
               If $right_cod_ora <= 7 Then
                     $room_status=2 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 2
                     ExitLoop
                  EndIf
               Case 3
                  If $right_cod_ora <= 9 Then
                     $room_status=3 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 3
                     ExitLoop
                  EndIf
               Case 4
                  $room_status=4 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 4
                  ExitLoop
               Case 5
                  If $right_cod_ora >= 2 AND $right_cod_ora <= 7 Then
                     $room_status=5 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 5
                     ExitLoop
                  EndIf
               Case 6
                  If $right_cod_ora >= 2 AND $right_cod_ora <= 9 Then
                     $room_status=6 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 6
                     ExitLoop
                  EndIf
               Case 7
                  If $right_cod_ora >= 2 AND $right_cod_ora <= 9 OR $right_cod_ora = 0 Then
                     $room_status=7 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 7
                     ExitLoop
                  EndIf
               Case 8
                  If $right_cod_ora =1 OR $right_cod_ora =2 OR $right_cod_ora =5 OR $right_cod_ora =0 Then
                     $room_status=0 ;BOOKING ACCEPT -> Confermare prenotazione
                  Else
                     $room_status=8 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 8
                     ExitLoop
                  EndIf
               Case 9
                  If $right_cod_ora =1 OR $right_cod_ora =2 OR $right_cod_ora =5 Then
                     $room_status=0 ;BOOKING ACCEPT -> Confermare prenotazione
                  Else
                     $room_status=9 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 9
                     ExitLoop
                  EndIf
               Case 0
                  If $right_cod_ora =1 OR $right_cod_ora =2 OR $right_cod_ora =3 OR $right_cod_ora =5 OR $right_cod_ora =6 OR $right_cod_ora =8 Then
                     $room_status=0 ;BOOKING ACCEPT -> Confermare prenotazione
                  Else
                     $room_status=10 ;BOOKING FAILURE -> Informare l'utente che la sala è occupata in fascia 10
                     ExitLoop
                  EndIf
               EndSwitch
            EndIf
         EndIf
   Next
   If $room_status>0 Then
      MsgBox(48,"Prenotazione fallita","La combinazione data/orario/posto scelta non è disponibile:"&@crlf&"("&$data_prenotazione&"-"&$ora_prenotazione&"-"&$posto_prenotazione&")"&@crlf&@crlf&"Conflitto con la seguente prenotazione:"&@crlf&"Data: "&$aResult[$i][0]&@crlf&"Orario: "&$aResult[$i][3]&@crlf&"Posto: "&$aResult[$i][4]&@crlf&"User: "&$aResult[$i][5])
      _GUICtrlEdit_AppendText($Console,"La combinazione data/orario/posto scelta non è disponibile:"&@crlf&"("&$data_prenotazione&"-"&$ora_prenotazione&"-"&$posto_prenotazione&")"&@crlf&@crlf&"Conflitto con la seguente prenotazione:"&@crlf&"Data: "&$aResult[$i][0]&@crlf&"Orario: "&$aResult[$i][3]&@crlf&"Posto: "&$aResult[$i][4]&@crlf&"User: "&$aResult[$i][5]&@crlf)
   EndIf
   Return $room_status
EndFunc

Func Prenota()
   _GUICtrlEdit_SetText($Console,"Relax Room Booking Tool Console"&@crlf)
   Global $data_prenotazione = GUICtrlRead($Date1)
   Global $username = @UserName
   Global $cod_ora_prenotazione = _GUICtrlComboBox_GetCurSel($Combo1)
   $cod_ora_prenotazione = $cod_ora_prenotazione+1
   Global $ora_prenotazione = $lista_orari[$cod_ora_prenotazione]
   Global $fascia_prenotazione
   If $cod_ora_prenotazione <= 10 Then
      $fascia_prenotazione = "Mattina"
      Consolewrite("Stai prenotando la mattina"&@crlf)
   ElseIf $cod_ora_prenotazione <= 20 Then
      $fascia_prenotazione = "Pranzo"
      Consolewrite("Stai prenotando il pranzo"&@crlf)
   Else
      $fascia_prenotazione = "Sera"
      Consolewrite("Stai prenotando la sera"&@crlf)
   EndIf
   Local $posto=_GUICtrlComboBox_GetCurSel($Combo2)
   $posto = $posto+1
   $posto_prenotazione = $lista_posti[$posto]
   Local $AreYouSure=MsgBox(4,"Prenotazione Relax Room","Conferma che i dati sono corretti:"&@crlf&"Giorno: "&$data_prenotazione& " - Orario: "&$lista_orari[$cod_ora_prenotazione]&" - Posto: "&$posto_prenotazione&" - Utente: "&$username)
   If $AreYouSure = 6 Then
      _GUICtrlEdit_AppendText($Console,@crlf)
      Local $pass_i
      $pass_prenotazione=""
      For  $pass_i = 1 To 6
        $pass_prenotazione &= Random(0, 9, 1) ;Generate random passcode
      Next
      $aPrenotazione = "'"&$data_prenotazione&"','"&$fascia_prenotazione&"','"&$cod_ora_prenotazione&"','"&$ora_prenotazione&"','"&$posto_prenotazione&"','"&$username&"','"&$pass_prenotazione&"'"
      ;Read the database, look for bookings on given Date
      ReadDB()
      ;Launch Function to check if room is free in given date/time/seat
      Local $check=CheckIfRoomIsFree($fascia_prenotazione,$posto_prenotazione)
      IF $check = 0 Then
         WriteDB($aPrenotazione)
         GUISetState(@SW_HIDE,$GUI_Prenota)
      EndIf
   Else
      MsgBox(0,"Prenotazione Relax Room","La prenotazione è stata annullata")
   EndIf
EndFunc

Func MyBook_Verifica()
   Local $data = GUICtrlRead($Date_MyBook)
   Local $iRows, $iColumns, $iRval

   _SQLite_Startup("sqlite3.dll")
   If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)

   Local $hDB = _SQLite_Open($DB)    ; for a memory DB or _SQLite_Open("myDB.sq3") for a disk-based DB
   If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   If _SQLite_ErrMsg()="database is locked" Then
      MsgBox(64,"Database bloccato","Il database è in uso da un'altro utente, riprovare più tardi.",5)
   EndIf

   $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Booking WHERE data_prenotazione = '"&$data&"' AND username = '"&@UserName&"';", $aResult, $iRows, $iColumns)
   _SQLite_Close()
   _SQLite_Shutdown()
   If $iRval = $SQLITE_OK Then
      Local $text_display
      For $i = 1 to Ubound($aResult)-1
         $text_display &=@crlf & " - - - " & @crlf & $aResult[$i][3] & " - " & $aResult[$i][4] & " - " & $aResult[$i][5] & " - Codice Prenotazione: " & $aResult[$i][6]
      Next
      If $text_display = "" Then
         GUICtrlSetData($Edit_MyBook,"Non ci sono prenotazioni a tuo nome nella data selezionata ( "&$data&" ).")
      Else
         GUICtrlSetData($Edit_MyBook,"Le tue prenotazioni per la data selezionata: ( "&$data&" ):"&@crlf&$text_display)
      EndIf
   Else
      MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
   EndIf

EndFunc

Func DeleteDB()
   Local $pass = GUICtrlRead($pass_delete)
   If $pass = "" OR StringLen($pass)<6 Then
      MsgBox(48,"Relax Room - Cancella prenotazione","Il codice prenotazione inserito non è valido.")
      Return
   EndIf

   Local $iRows, $iColumns, $iRval
   _SQLite_Startup("sqlite3.dll")
   If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)

   Local $hDB = _SQLite_Open($DB)
   If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   If _SQLite_ErrMsg()="database is locked" Then
      MsgBox(64,"Database bloccato","Il database è in uso da un'altro utente, riprovare più tardi.",5)
   EndIf

   $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Booking WHERE pass_prenotazione = '"&$pass&"' AND username ='"&@UserName&"';", $aResult, $iRows, $iColumns)

   If $iRval = $SQLITE_OK Then

      Local $text_display
      For $i = 1 to Ubound($aResult)-1
         $text_display &=@crlf & $aResult[$i][0] & " - " & $aResult[$i][3] & " - " & $aResult[$i][4] & " - " & $aResult[$i][5]
      Next
      If $text_display = "" Then
         MsgBox(48,"Relax Room - Cancella prenotazione","Non ci sono prenotazioni a tuo nome con questo codice.",5)
      Else
         Local $response = MsgBox(65,"Relax Room - Cancella prenotazione","Vuoi eliminare la seguente prenotazione:"&@crlf&$text_display,8)
         IF $response = 1 Then
            If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)

            _SQLite_Exec(-1, "DELETE FROM Booking WHERE pass_prenotazione = '"&$pass&"' AND username ='"&@UserName&"';")

            MsgBox(64,"Relax Room - Cancella prenotazione","La prenotazione è stata annullata",5)
            GUISetState(@SW_HIDE,$GUI_Delete)
         ElseIf $response = -1 Then
            MsgBox(64,"Relax Room - Cancella prenotazione","TIMEOUT: La prenotazione non è stata annullata",5)
         Else
            MsgBox(64,"Relax Room - Cancella prenotazione","La prenotazione non è stata eliminata.",5)
         EndIf
      EndIf
    Else
       MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
    EndIf
    _SQLite_Close()
   _SQLite_Shutdown()
EndFunc

While 1
   $nMsg = GUIGetMsg(1)
   Switch $nMsg[1]
   Case $GUI_Main
      Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
         Exit
      Case $Button_Prenota
         GUISetState(@SW_SHOW,$GUI_Prenota)
      Case $Button_Check
         GUISetState(@SW_SHOW,$GUI_Check)
      Case $Button_MyBook
         GUISetState(@SW_SHOW,$GUI_MyBook)
      Case $Button_Delete
         GUISetState(@SW_SHOW,$GUI_Delete)
      Case $Button_Exit
         Exit
      EndSwitch

   Case $GUI_Prenota
      Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
         GUISetState(@SW_HIDE,$GUI_Prenota)
         GUICtrlSetState($Button_Prenota, $GUI_ENABLE)
      Case $Button_Annulla_Prenotazione
         GUISetState(@SW_HIDE,$GUI_Prenota)
         GUICtrlSetState($Button_Prenota, $GUI_ENABLE)
      Case $Button_Conferma_Prenotazione
         If GUICtrlRead($Combo1) = "" Then
            MsgBox(48,"Selezione non valida","Devi selezionare un orario dal menu a tendina.")
         ElseIF GUICtrlRead($Combo2) = "" Then
            MsgBox(48,"Selezione non valida","Devi selezionare un posto dal menu a tendina")
         Else
            GUICtrlSetState($Button_Conferma_Prenotazione, $GUI_DISABLE)
            Prenota()
            GUICtrlSetState($Button_Conferma_Prenotazione, $GUI_ENABLE)
         EndIf
      EndSwitch

   Case $GUI_Check
      Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
         GUISetState(@SW_HIDE,$GUI_Check)
      Case $Button_Check_Verifica
         GUICtrlSetState($Button_Check_Verifica, $GUI_DISABLE)
         CheckDB()
         GUICtrlSetState($Button_Check_Verifica, $GUI_ENABLE)
      Case $Button_Check_Annulla
         GUISetState(@SW_HIDE,$GUI_Check)
      EndSwitch

   Case $GUI_MyBook
      Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
         GUISetState(@SW_HIDE,$GUI_MyBook)
      Case $Button_MyBook_Annulla
         GUISetState(@SW_HIDE,$GUI_MyBook)
      Case $Button_MyBook_Verifica
         GUICtrlSetState($Button_MyBook_Verifica, $GUI_DISABLE)
         MyBook_Verifica()
         GUICtrlSetState($Button_MyBook_Verifica, $GUI_ENABLE)
      EndSwitch

   Case $GUI_Delete
      Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
         GUISetState(@SW_HIDE,$GUI_Delete)
      Case $Button_Delete_Annulla
         GUISetState(@SW_HIDE,$GUI_Delete)
      Case $Button_Delete_Conferma
         GUICtrlSetState($Button_Delete_Conferma, $GUI_DISABLE)
         DeleteDB()
         GUICtrlSetState($Button_Delete_Conferma, $GUI_ENABLE)
      EndSwitch
   EndSwitch
WEnd


 

Edited by r3dbullo88

Share this post


Link to post
Share on other sites
r3dbullo88

Any suggestions?

Share this post


Link to post
Share on other sites
spudw2k

Without diving too deep into the code a couple of things came to mind.  Firstly your pre-defined schedules.  I was looking to see if there was a pattern...best I could tell, the following conditions are representative of the schedules you are enabling:

  1. Nothing before 07:00 and nothing after 20:00 can be scheduled.
  2. A booking cannot exceed 2 hours and is booked in 30 min increments.
  3. 09:00 - 12:00 is blocked out, as well as from 14:00 - 18:00.

If all of those statements are true and all encompassing, you could build logic to enforce those conditions instead of defining each unique schedule. 

Secondly, in the CheckRoomFree func it looks like there is potential to optimize the stack of if statements.  Once again without diving into it...I don't have any specific suggestions other than the following:

You use StringRight over and over in that loop.  You'd might be better suited to set a variable to the return value of StringRight and then evaluate the variable instead of re-running StringRight every time.  Here's a crude example (pseudo-code...notional/non-functional):

$sLocation = "Location2"
$iLocationValue = StringRight($sLocation,1)

Switch ;....
    Case 1
        If $iLocationValue = ;....
    Case 2
        If $iLocationValue <= ;.....

 

Edited by spudw2k

Share this post


Link to post
Share on other sites
r3dbullo88

Thank you for your thoughts spudw2k,

I will fix right now that abuse of StringRight function, and then will work back towards a better way of handling the schedule possibilities.

Will update once done.

 

Update:

Probably I should split booking times in "booking_start" and "booking_end", in order to perform the checks better.

Luciano

 

Edited by r3dbullo88

Share this post


Link to post
Share on other sites
r3dbullo88

I've updated the first post as I completed the script with all the functions that were missing.

I am now facing the logical aspect of the time scheduling and actually found what it seems to be a good workaround.

With this method I could completely avoid the CheckIfRoomIsFree() function, so less lines but abuse of StringLeft & Right...

Any thoughts on this?

Func ReadDB()
   Local $booking_time= ---> Get from GuiCtrlRead
   Local $DB="K:\Public Folder\Italy IT\Relax Room\testDB.db"
   Local $iRows, $iColumns, $iRval,$aResult
   _SQLite_Startup("sqlite3.dll")
   If @error Then Exit MsgBox(17, 'Startup Error', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   Local $hDB = _SQLite_Open($DB)
   If @error Then Exit MsgBox(17, 'DB open failed', '@ERROR = ' & @error & @CRLF & '@EXTENDED = ' & @extended)
   If _SQLite_ErrMsg()="database is locked" Then
      MsgBox(64,"Database bloccato","Il database è in uso da un'altro utente, riprovare più tardi.",5)
   EndIf
   $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Booking WHERE data_prenotazione = '----> Get From GuiCtrlRead';", $aResult, $iRows, $iColumns)
   _SQLite_Close()
   _SQLite_Shutdown()

   For $i=1 to Ubound($aResult)-1
      ;Separate Hours & Minutes
      $booked_sh = StringLeft($aResult[$i][3],2)
      $booked_sm = StringLeft($aResult[$i][3],5)
      $booked_sm = StringRight($booked_sm,2)
      $booked_eh = StringRight($aResult[$i][3],5)
      $booked_eh = StringLeft($booked_eh,2)
      $booked_em = StringRight($aResult[$i][3],2)

      $booking_sh = StringLeft($booking_time,2)
      $booking_sm = StringLeft($booking_time,5)
      $booking_sm = StringRight($booking_sm,2)
      $booking_eh = StringRight($booking_time,5)
      $booking_eh = StringLeft($booking_eh,2)
      $booking_em = StringRight($booking_time,2)

      ;Compare
      If $booking_sh > $booked_sh AND $booking_sh >= $booked_eh Then
         ConsoleWrite("La mia prenotazione "&$booking_time&" non è in conflitto con la prenotazione "&$i&": "&$aResult[$i][3]&@crlf)
      ElseIf $booking_eh < $booked_sh Then
         ConsoleWrite("La mia prenotazione "&$booking_time&" non è in conflitto con la prenotazione "&$i&": "&$aResult[$i][3]&@crlf)
      ElseIf $booking_sh >= $booked_sh AND $booking_eh <= $booked_eh Then
         ConsoleWrite("La mia prenotazione "&$booking_time&" è in conflitto con la prenotazione "&$i&": "&$aResult[$i][3]&@crlf)
      Else
         ConsoleWrite("La mia prenotazione "&$booking_time&" non è in conflitto con la prenotazione "&$i&": "&$aResult[$i][3]&@crlf)
      EndIf
   Next
EndFunc

 

Edited by r3dbullo88

Share this post


Link to post
Share on other sites
spudw2k

Well, arguably the most sophisticated way to parse your booking time would be to use Regular Expressions, but I'm no regex expert.  Another option is the StringMid function.  It allows you to extract characters from a string (from left-to-right) at a specified location and length.  You could use that to grab parts of the string in one step instead of grabbing the left side of a string and subsequently the right. 

Share this post


Link to post
Share on other sites
coffeeturtle
On 10/19/2016 at 9:19 AM, r3dbullo88 said:

Any suggestions?

would you mind providing your test.db so we can give it a run?

Share this post


Link to post
Share on other sites
r3dbullo88

Sure, here it is.

I will have to do some changes, because the "Business" is asking me couple changes.

The new request is to have people book a maximum of 30 minutes, therefore a lot of complications go away :) 

 

testDB.db

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • RamDemon
      By RamDemon
      Hi,
      Did anyone tried to  use Redis  with AutoIT as store DB ?
       Redis <-- more about it
      Mladen
    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
    • Miliardsto
      By Miliardsto
      Hello Im wondering if using this https://ohtejera.github.io/ImperiusAutoIt/#started
      UDF can i make that I can control my windows application with phone?
      like for example click button Start on android phone and then something would be done in my windows app?
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
    • iMacg3
      By iMacg3
      Hi,
      I was looking into a way to delete a registry key (not a specific value, an entire key) if it is present. I was considering using RegRead and RegDelete. However, RegRead appears to only read values, not just keys. Is there a way to delete an entire registry key if it is present? I have heard that the below function may help.
       
      #include-once ; #UDF# ======================================================================================================================= ; Title .........: Reads\Search the name of a Key\Subkey\Value ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists all Keys\Subkeys\Values in a specified registry key ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _RegEnumKeyEx ;~ _RegEnumValEx ; =============================================================================================================================== #Region ;**** Global constants and vars **** Global Const $sValueTypes[12] = ["REG_NONE","REG_SZ","REG_EXPAND_SZ","REG_BINARY","REG_DWORD","REG_DWORD_BIG_ENDIAN","REG_LINK","REG_MULTI_SZ","REG_RESOURCE_LIST","REG_FULL_RESOURCE_DESCRIPTOR","REG_RESOURCE_REQUIREMENTS_LIST","REG_QWORD"] #EndRegion ;**** Global constants and vars **** ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumKeyEx ; Description ...: Lists all subkeys in a specified registry key ; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read. ; $iFlag - Optional specifies Recursion (add the flags together for multiple operations): ; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod ; |$iFlag = 1 All SubKeys Not Recursive Mod ; |$iFlag = 2 Include in ArrayList in the first element $KeyName ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 128 Enum value's name (_RegEnumKeyEx Return a 2D array, maximum Array Size limit is 3999744 Key\Value) ; |$iFlag = 256 Reads a value data, this flag will be ignored if the $iFlag = 128 is not set ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $vFilter - Optional the filter to use for ValueName, $vFilter will be ignored if the $iFlag = 128 is not set ; default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All), $iValueTypes will be ignored if the $iFlag = 128 is not set ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |1 = Invalid $sFilter ; |2 = No Key-SubKey(s) Found ; |3 = Invalid $vFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Key-SubKeys returned ; $array[1] = 1st Key\SubKeys ; $array[2] = 2nd Key\SubKeys ; $array[3] = 3rd Key\SubKeys ; $array[n] = nth Key\SubKeys ; ; If is set the $iFlag = 128 The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumValEx() ; Link ..........: ; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*", $vFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, StringReplace("^\s*$|\v|\\|^\||\|\||\|$", Chr(BitAND($iFlag, 64) + 28) & "\|^\||\|\||\|$", "\\\\")) Then Return SetError(1, 0, "") Local $IndexSubKey[101] = [100], $SubKeyName, $BS = "\", $sKeyList, $I = 1, $sKeyFlag = BitAND($iFlag, 1), $sKeyFilter = StringReplace($sFilter, "*", "") If BitAND($iFlag, 2) Then $sKeyList = @LF & $KeyName If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While $I $IndexSubKey[$I] += 1 $SubKeyName = RegEnumKey($KeyName, $IndexSubKey[$I]) If @error Then $IndexSubKey[$I] = 0 $I -= 1 $KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1) ContinueLoop EndIf If $sKeyFilter Then If StringRegExp($SubKeyName, $sFilter) Then $sKeyList &= @LF & $KeyName & $BS & $SubKeyName Else $sKeyList &= @LF & $KeyName & $BS & $SubKeyName EndIf If $sKeyFlag Then ContinueLoop $I += 1 If $I > $IndexSubKey[0] Then $IndexSubKey[0] += 100 ReDim $IndexSubKey[$IndexSubKey[0] + 1] EndIf $KeyName &= $BS & $SubKeyName WEnd If Not $sKeyList Then Return SetError(2, 0, "") If BitAND($iFlag, 128) <> 128 Then Return StringSplit(StringTrimLeft($sKeyList, 1), @LF, StringReplace(BitAND($iFlag, 32), "32", 2)) $sKeyList = _RegEnumValEx(StringSplit(StringTrimLeft($sKeyList, 1), @LF), $iFlag, $vFilter, $iValueTypes) Return SetError(@Error, 0, $sKeyList) EndFunc ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumValEx ; Description ...: Lists all values in a specified registry key ; Syntax.........: _RegEnumValEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read Or one-dimensional array RegKeyList ; use _RegEnumKeyEx() to get $RegKeyList (example $RegKeyList = [3, 1st Key\SubKeys, 2st Key\SubKeys, nth Key\SubKeys]) ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 256 Reads a value data ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All) ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |3 = Invalid $sFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumKeyEx() ; Link ..........: ; Example .......: _RegEnumValEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumValEx($aKeyList, $iFlag = 0, $sFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, "\v") Then Return SetError(3, 0, "") If Not IsArray($aKeyList) Then $aKeyList = StringSplit($aKeyList, @LF) Local $aKeyValList[1954][4], $iKeyVal = Int(BitAND($iFlag, 32) = 0), $sKeyVal = 1953, $sRegEnumVal, $iRegEnumVal, $RegRead = BitAND($iFlag, 256), $vFilter = StringReplace($sFilter, "*", "") If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" For $i = 1 To $aKeyList[0] $iRegEnumVal = 0 While 1 If $iKeyVal = $sKeyVal Then If $sKeyVal = 3999744 Then ExitLoop $sKeyVal *= 2 ReDim $aKeyValList[$sKeyVal + 1][4] EndIf $aKeyValList[$iKeyVal][0] = $aKeyList[$i] $iRegEnumVal += 1 $sRegEnumVal = RegEnumVal($aKeyList[$i], $iRegEnumVal) If @Error <> 0 Then If $iRegEnumVal = 1 And $vFilter = "" Then $iKeyVal += 1 ExitLoop EndIf $aKeyValList[$iKeyVal][2] = $sValueTypes[@Extended] If BitAND(@Extended, $iValueTypes) <> $iValueTypes Then ContinueLoop If $vFilter And Not StringRegExp($sRegEnumVal, $sFilter) Then ContinueLoop $aKeyValList[$iKeyVal][1] = $sRegEnumVal If $RegRead Then $aKeyValList[$iKeyVal][3] = RegRead($aKeyList[$i], $sRegEnumVal) $iKeyVal += 1 WEnd Next $sRegEnumVal = $iKeyVal - Int(BitAND($iFlag, 32) = 0) If Not $sRegEnumVal Or ($sRegEnumVal = 1 And $vFilter = "" And $aKeyValList[$iKeyVal - $sRegEnumVal][2] = "") Then Return SetError(4, 0, "") ReDim $aKeyValList[$iKeyVal][4] If Not BitAND($iFlag, 32) Then $aKeyValList[0][0] = $iKeyVal - 1 Return $aKeyValList EndFunc Thanks.
       
×