BitByteBit Posted March 2, 2010 Share Posted March 2, 2010 (edited) Hi there, I have a listview control on my gui, I'm populating this with data from a 2d array. I know that for each list view item I set, a control handle is returned, and should I want to listen for this control, that I need to save it to a variable, my problem is that I'm using a for to next loop, so only the last item's handle is saved to my variable, how do I create a new variable for each item, and how do I listen for all of them in my while loop? expandcollapse popupFunc PopGUI() ;PopulateArray() If $StudentArray[0][0] > 0 Then GUICtrlSetData($TotalDaysMissed, 0) GUICtrlSetData($StudentList, "") GUICtrlSetData($DateList, "") For $X = 1 To $StudentArray[0][0] $Students = GUICtrlCreateListViewItem( $StudentArray[$X][0]&"|"&$AttendanceRecord[$x][1],$StudentList) ;Here is my problem ;GUICtrlSetOnEvent($Students, "HandleClicks") Next Else PopulateArray() PopGUI() EndIf SetWarningLevel() ;_ArrayDisplay($StudentArray) EndFunc ;==>PopGUI Func PopulateArray() $TheMasterComplex = IniReadSectionNames($File) ;Read DB $AttendanceRecord[0][0] = 0 If Not @error Then ReDim $StudentArray[1][1] ReDim $AttendanceRecord[1][1] For $X = 1 To $TheMasterComplex[0] $DecryptedName = _StringEncrypt(0, $TheMasterComplex[$X], $HashKey) ;Decrypt Student names ReDim $StudentArray[UBound($StudentArray, 1) + 1][1] ;Resize student array ReDim $AttendanceRecord[UBound($AttendanceRecord, 1) + 1][2] ;Resize attendance array $StudentArray[$X][0] = $DecryptedName $StudentArray[0][0] = $X ;[0][0] = Total Number of students [x][0] = Name [x][1] = First Absent Date $AttendanceRecord[$X][0] = $DecryptedName ;_ArrayDisplay($AttendanceRecord) ;_ArrayDisplay($StudentArray) Next For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student If Not @error Then If $Dates[0][0] >= UBound($StudentArray, 2) - 1 Then ReDim $StudentArray[UBound($StudentArray, 1)][$Dates[0][0] + 1];UBound($StudentArray,2) + 1 For $Z = 1 To $Dates[0][0] $DecryptedDates = _StringEncrypt(0, $Dates[$Z][1], $HashKey) ;Decrypt first date $StudentArray[$X][$Z] = $DecryptedDates $AttendanceRecord[$X][1] = $Z ;$TotalD1 += 1 $StudentArray[0][1] += 1 ;Total Days missed Next If $Z > $AttendanceRecord[0][1] Then $AttendanceRecord[0][0] = $StudentArray[$X][0] ;Student name with the higest days absent $AttendanceRecord[0][1] = $Z - 1 ;Total Number of warnings ;MsgBox(0,"",$Z) ;MsgBox(0,"",$AttendanceRecord[$X][0]) EndIf EndIf Next ;_ArraySort($StudentArray) EndIf ;_ArrayDisplay($StudentArray) ;_ArrayDisplay($AttendanceRecord) _ArraySort($StudentArray, 0, 1) _ArraySort($AttendanceRecord, 0, 1) EndFunc ;==>PopulateArray Full source code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=DG.ico #AutoIt3Wrapper_outfile=DG Encrypted DB.exe #AutoIt3Wrapper_Compression=4 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** HotKeySet("!a", "PopulateArray2") #Region ;**** Declarations, Includes and Options #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #include <array.au3> #include <ie.au3> ;Opt("GUIDataSeparatorChar","@crlf") Opt("TrayIconDebug", 1) Global $StudentArray[1][1] Global $AttendanceRecord[1][2] $HashKey = "1234554321" $File = @ScriptDir& "\Database.ini" $MenuRadio = 0 $Sorted = False dim $Students #EndRegion ;**** Declarations, Includes and Options #Region ;**** GUI section TrayTip("", "Loading Database..", 1) $Form1_1 = GUICreate("Student Attendance Tracker", 505, 318, 192, 114, $WS_MINIMIZEBOX + $WS_MAXIMIZEBOX + $WS_SYSMENU + $WS_SIZEBOX) GUISetIcon(@ScriptDir&"\DG.ico") TraySetIcon(@ScriptDir&"\DG.ico") GUISetBkColor(0x34534C) GUISetFont(-1, 9, 400, 0, "Verdana") GUICtrlSetColor(-1, 0xFFFFFF) $filemenu = GUICtrlCreateMenu("&File") GUICtrlSetBkColor($filemenu ,0x34534C) $Open = GUICtrlCreateMenuItem("Open", $filemenu) $Encrypt = GUICtrlCreateMenuItem("Encrypt Database", $filemenu) $Decrypt = GUICtrlCreateMenuItem("Decrypt Database", $filemenu) ;$FixIndex = GUICtrlCreateMenuItem("Repair Database", $filemenu) $StudentMenu = GUICtrlCreateMenu("&Students") $NewStudent = GUICtrlCreateMenuItem("Add Student", $StudentMenu) $EditStudentMenu = GUICtrlCreateMenuItem("Edit Student Name", $StudentMenu) $DeleteStudent = GUICtrlCreateMenuItem("Delete current student", $StudentMenu) $ViewAll = GUICtrlCreateMenuItem("View all", $StudentMenu) $DateMenu = GUICtrlCreateMenu("&Date Management") $NewDateMenu = GUICtrlCreateMenuItem("Add date", $DateMenu) $RemoveDateMenu = GUICtrlCreateMenuItem("Delete date", $DateMenu) $ViewTotals = GUICtrlCreateMenuItem("View totals", $DateMenu, 0, 1) $SortTotals = GUICtrlCreateMenuItem("Sort totals by name", $DateMenu) $SortTotals1 = GUICtrlCreateMenuItem("Sort totals by absence", $DateMenu) $M = GUICtrlCreateGroup("Student Case Viewer", 15, 0, 481, 270) GUICtrlSetFont(-1, 10, 400, 0, "Verdana") GUICtrlSetColor($M, 0xFFFFFF) GUICtrlCreateLabel("Students", 30, 15, 70, 17) GUICtrlSetFont(-1, 9, 400, 0, "Verdana") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateLabel("Dates", 260, 15, 32, 17) GUICtrlSetFont(-1, 9, 400, 0, "Verdana") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateLabel("Comments", 224, 131, 100, 50) GUICtrlSetFont(-1, 9, 400, 0, "Verdana") GUICtrlSetColor(-1, 0xFFFFFF) $DaysMissedLabel = GUICtrlCreateLabel("Total Days: ", 380, 15, 100, 17); Absent GUICtrlSetFont(-1, 9, 200, 0, "Verdana") GUICtrlSetColor(-1, 0xFFFFFF) $TotalDaysMissed = GUICtrlCreateInput("0", 455, 12, 21, 21, BitOR($ES_CENTER, $ES_NUMBER)) $DateList = GUICtrlCreateList("", 256, 35, 225, 97) GUICtrlSetFont(-1, 10, 400, 0, "Verdana") GUICtrlCreateContextMenu($DateList) $StudentList = GUICtrlCreateListView("Students |Days Missed", 24, 35, 225, 97) ;$StudentList = GUICtrlCreateList("Students", 24, 35, 225, 97) ;#Include <GuiListView.au3> ;$StudentList = _GUICtrlListView_Create($Form1_1,"Students |Days Missed", 24, 35, 225, 97) ;GUICtrlSetFont(-1, 10, 400, 0, "Verdana") ;GUICtrlSetColor(-1, 0xFFFFFF) ;GUICtrlSetBkColor($StudentList, 0x8C1025) GUICtrlCreateContextMenu($StudentList) ;GUICtrlSetBkColor($StudentList,0x8C1025) $CommentBox = GUICtrlCreateEdit("", 32, 145, 440, 90) GUICtrlSetFont(-1, 9, 400, 0, "Verdana") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor($CommentBox, 0x8C1025) $MenuNewStudent = GUICtrlCreateMenuItem("&Add Student", $StudentList) $EditStudent = GUICtrlCreateMenuItem("Edit Student Name", $StudentList) $MenuDeleteStudent = GUICtrlCreateMenuItem("&Delete Student", $StudentList) $MenuAddDate = GUICtrlCreateMenuItem("&Add date", $DateList) $MenuEditDate = GUICtrlCreateMenuItem("&Edit date", $DateList) $MenuDeleteDate = GUICtrlCreateMenuItem("&Delete Date", $DateList) PopGUI() GUISetState(@SW_SHOW) TrayTip("", "Loaded Database!", 1) #EndRegion ### END Koda GUI section ### #Region ;**** Main While Loop While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $SortTotals1 SortTotals() Case $GUI_EVENT_CLOSE Exit Case $Open Open() Case $NewStudent NewStudent() Case $Students $SelectedStudent = GUICtrlRead(GUICtrlRead($StudentList)) MsgBox(0,"1",$SelectedStudent ) Case $StudentList GUICtrlSetData($TotalDaysMissed, "") GUICtrlSetData($DateList, "") $SelectedStudent = GUICtrlRead($StudentList) ;$SelectedStudent = GUICtrlGetState($StudentList) MsgBox(0,"2",$SelectedStudent ) If $Sorted = True Then $SelectedStudent1 = StringSplit($SelectedStudent, " - ", 1) $SelectedStudent = $SelectedStudent1[1] ;_ArrayDisplay($SelectedStudent ) If Not @error Then For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then For $y = 1 To $AttendanceRecord[$X][1] GUICtrlSetData($DateList, $StudentArray[$X][$y]) GUICtrlSetData($TotalDaysMissed, GUICtrlRead($TotalDaysMissed) + 1) Next EndIf Next SetWarningLevel() Else PopulateArray() PopGUI() EndIf Else For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then For $y = 1 To $AttendanceRecord[$X][1] GUICtrlSetData($DateList, $StudentArray[$X][$y]) GUICtrlSetData($TotalDaysMissed, GUICtrlRead($TotalDaysMissed) + 1) Next EndIf Next SetWarningLevel() EndIf Case $DeleteStudent Delete() ;PopGUI() ;_ArrayDisplay($StudentArray) Case $MenuDeleteDate Rosie() ;DeleteDate() ;PopGUI() Case $MenuNewStudent NewStudent() Case $MenuDeleteStudent Delete() Case $EditStudent EditStudentName() Case $EditStudentMenu EditStudentName() Case $MenuAddDate AddDate() SetWarningLevel() Case $NewDateMenu AddDate() SetWarningLevel() Case $MenuDeleteDate ;DeleteDate() Rosie() ;PopGUI() SetWarningLevel() Case $RemoveDateMenu ;DeleteDate() Rosie() ;PopGUI() SetWarningLevel() Case $Decrypt Decrypt() Case $Encrypt encrypt() Case $MenuEditDate EditDate() Case $ViewAll ViewAll() Case $ViewTotals ViewTotals() EndSwitch WEnd #EndRegion ;**** Main While Loop #Region ;**** File Managment Func Open() $File = FileOpenDialog("Select database file to open:", "C:\Program Files\", "Encrypted .ini: (*.ini)", 8) PopulateArray() PopGUI() EndFunc ;==>Open #EndRegion ;**** File Managment #Region ;**** Student Managment Func NewStudent() $Name = InputBox("Name of Student.", "Type in name of student") If $Name <> "" Then If Not @error Then $Q = MsgBox(4, "", "Has the student been absent?") If $Q = 6 Then $Date = InputBox("Enter absent date.", "Type in the day the student was absent", @YEAR & "\" & @MON & "\" & @MDAY) If Not @error Then $EncryptedDate = _StringEncrypt(1, $Date, $HashKey) $EncryptedName = _StringEncrypt(1, $Name, $HashKey) $Write = IniWriteSection($File, $EncryptedName, "1=" & $EncryptedDate) ReDim $StudentArray[UBound($StudentArray, 1) + 1][UBound($StudentArray, 2)] ReDim $AttendanceRecord[UBound($AttendanceRecord, 1) + 1][2] $StudentArray[UBound($StudentArray, 1) - 1][0] = $Name $StudentArray[UBound($StudentArray, 1) - 1][1] = $Date $AttendanceRecord[UBound($StudentArray, 1) - 1][0] = $Name $AttendanceRecord[UBound($StudentArray, 1) - 1][1] = 1 $StudentArray[0][0] += 1 GUICtrlSetData($DateList, "") GUICtrlSetData($DateList, $Date) ;GUICtrlSetData($Students, $Name) GUICtrlCreateListViewItem( $Name&"|"&"1",$StudentList) ;GUICtrlSetData($StudentList, $Name) GUICtrlSetData($TotalDaysMissed, 1) ;PopGUI() Else $EncryptedName = _StringEncrypt(1, $Name, $HashKey) IniWriteSection($File, $EncryptedName, " ") ReDim $StudentArray[UBound($StudentArray, 1) + 1][UBound($StudentArray, 2)] $StudentArray[UBound($StudentArray, 1) - 1][0] = $Name $StudentArray[0][0] += 1 GUICtrlSetData($StudentList, $Name) EndIf Else $EncryptedName = _StringEncrypt(1, $Name, $HashKey) IniWriteSection($File, $EncryptedName, " ") ReDim $StudentArray[UBound($StudentArray, 1) + 1][UBound($StudentArray, 2)] $StudentArray[UBound($StudentArray, 1) - 1][0] = $Name $StudentArray[0][0] += 1 GUICtrlSetData($StudentList, $Name) ;PopGUI() EndIf Else ToolTip("Canceled") Sleep(750) ToolTip("") EndIf Else MsgBox(0, "", "Please type in a name") NewStudent() EndIf EndFunc ;==>NewStudent Func EditStudentName() $SelectedStudent = GUICtrlRead($StudentList) If $SelectedStudent <> "" Then $Q = MsgBox(4, "", 'Do you want to you want to rename: ' & '"' & $SelectedStudent & '"?') If $Q = 6 Then $NewName = InputBox("Edit Name", "Please enter a new name", $SelectedStudent) $CryptedName = _StringEncrypt(1, $NewName, $HashKey) $hKey = _StringEncrypt(1, $SelectedStudent, $HashKey) IniRenameSection($File, $hKey, $CryptedName) For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then $StudentArray[$X][0] = $NewName EndIf Next PopGUI() EndIf Else MsgBox(0, "", "Please select a student first.") EndIf EndFunc ;==>EditStudentName Func Delete() $SelectedStudent = GUICtrlRead($StudentList) If $SelectedStudent <> "" Then $Q = MsgBox(4, "", 'Are you sure you want to delete: ' & '"' & $SelectedStudent & '"?') If $Q = 6 Then $hKey = _StringEncrypt(1, $SelectedStudent, $HashKey) Sleep(5) IniDelete($File, $hKey) For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then _ArrayDelete($StudentArray, $X) _ArrayDelete($AttendanceRecord, $X) ;_ArrayDisplay($StudentArray) $StudentArray[0][0] -= 1 ExitLoop EndIf Next ;$StudentArray[0][0] = UBound($StudentArray, 1) - 1 PopGUI() EndIf Else MsgBox(0, "", "Please select a student first", 4) EndIf EndFunc ;==>Delete #EndRegion ;**** Student Managment #Region ;**** Date Managment Func SortTotals2() ;$Test = GUICtrlGetState($SortTotals1) ;MsgBox(0,"",$Test) ;GUISetState($SortTotals1,1) ;_ArrayDisplay($AttendanceRecord) Local $SwapTemp[UBound($AttendanceRecord, 1)][2] For $X = 0 To UBound($AttendanceRecord, 1) - 1 $SwapTemp[$X][0] = $AttendanceRecord[$X][0] $SwapTemp[$X][1] = $AttendanceRecord[$X][1] Next If $MenuRadio = 1 Then _ArraySort($SwapTemp, 0, 1, UBound($AttendanceRecord, 1) - 1, 1) _ArrayDisplay($SwapTemp) $MenuRadio = 0 Else _ArraySort($SwapTemp, 1, 1, UBound($AttendanceRecord, 1) - 1, 1) _ArrayDisplay($SwapTemp) $MenuRadio = 1 EndIf EndFunc ;==>SortTotals2 Func SortTotals() Local $SwapTemp[UBound($AttendanceRecord, 1)][2] For $X = 0 To UBound($AttendanceRecord, 1) - 1 $SwapTemp[$X][0] = $AttendanceRecord[$X][0] $SwapTemp[$X][1] = $AttendanceRecord[$X][1] Next _ArraySort($SwapTemp, 1, 1, UBound($AttendanceRecord, 1) - 1, 1) _ArrayDisplay($SwapTemp) GUICtrlSetData($StudentList, "") For $X = 1 To UBound($SwapTemp, 1) - 1 ;MsgBox(0,"", $SwapTemp[$X][0] & " - " & $X) GUICtrlSetData($StudentList, $SwapTemp[$X][0] & " - " & $SwapTemp[$X][1]) Next $Sorted = True EndFunc ;==>SortTotals Func SortNames() ;$Test = GUICtrlGetState($SortTotals1) ;MsgBox(0,"",$Test) ;GUISetState($SortTotals1,1) ;_ArrayDisplay($AttendanceRecord) _ArraySort($AttendanceRecord, 1, 1, UBound($AttendanceRecord, 1) - 1, 1) _ArrayDisplay($AttendanceRecord) EndFunc ;==>SortNames Func AddDate() $SelectedStudent = GUICtrlRead($StudentList) If $SelectedStudent <> "" Then $hKey = _StringEncrypt(1, $SelectedStudent, $HashKey) ;Student name hashed $NewDatePlaintext = InputBox("New Date", "Please enter a new date", @YEAR & "\" & @MON & "\" & @MDAY);Default todays date If Not @error Then For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then If $AttendanceRecord[$X][1] + 1 >= UBound($StudentArray, 2) Then ReDim $StudentArray[UBound($StudentArray, 1)][UBound($StudentArray, 2) + 1];UBound($StudentArray,2) + 1 $StudentArray[$X][$AttendanceRecord[$X][1] + 1] = $NewDatePlaintext $AttendanceRecord[$X][1] += 1 $Previousposts = IniReadSection($File, $hKey) If Not @error Then IniWrite($File, $hKey, $Previousposts[0][0] + 1, _StringEncrypt(1, $NewDatePlaintext, $HashKey)) Else IniWrite($File, $hKey, 1, _StringEncrypt(1, $NewDatePlaintext, $HashKey)) EndIf EndIf Next ;PopGUI() GUICtrlSetData($TotalDaysMissed, GUICtrlRead($TotalDaysMissed) + 1) GUICtrlSetData($DateList, $NewDatePlaintext) _ArrayDisplay($StudentArray) Else ToolTip("Canceled") Sleep(750) ToolTip("") EndIf Else MsgBox(0, "", "Please select a student first.") EndIf ;_ArrayDisplay($AttendanceRecord) ;ReDim $StudentArray[UBound($StudentArray, 1)][UBound($StudentArray, 2)+1] ;MsgBox(0, "", $AttendanceRecord[$X][1]) ;MsgBox(0, "", UBound($StudentArray, 2) - 1) ;_ArrayDisplay($StudentArray) ;_ArrayDisplay($AttendanceRecord) ;_ArrayDisplay($StudentArray) ;MsgBox(0,"",$AttendanceRecord[$X][1] + 1) ;MsgBox(0,"",UBound($StudentArray, 1)) ;MsgBox(0,"",UBound($StudentArray, 2)+1) ;EndIf SetWarningLevel() EndFunc ;==>AddDate Func EditDate() $SelectedStudent = GUICtrlRead($StudentList) $SelectedDate = GUICtrlRead($DateList) If $SelectedStudent <> "" Then ;$Q = MsgBox(4, "", 'Do you want to you want to edtit: ' & '"' & $SelectedStudent & '"?') ;If $Q = 6 Then ;$StudentArray[$x][UBound($StudentArray, 1)] $NewDate = InputBox("Edit Name", "Please enter the new date", $SelectedDate) If Not @error Then $CryptedDate = _StringEncrypt(1, $NewDate, $HashKey) $hKey = _StringEncrypt(1, $SelectedStudent, $HashKey) For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then For $y = 1 To $StudentArray[0][0] If $StudentArray[$X][$y] = $SelectedDate Then $StudentArray[$X][$y] = $NewDate IniWrite($File, $hKey, $y, $CryptedDate) ExitLoop EndIf Next EndIf Next PopGUI() Else ToolTip("You canceled") Sleep(750) ToolTip("") EndIf Else MsgBox(0, "", "Please select a student first.") EndIf EndFunc ;==>EditDate Func Rosie() $Key = 0 $SelectedStudent = _StringEncrypt(1, GUICtrlRead($StudentList), $HashKey) $SelectedDate = _StringEncrypt(1, GUICtrlRead($DateList), $HashKey) $Sections = IniReadSectionNames($File) GUICtrlSetData($DateList, "") If Not @error Then For $X = 1 To $Sections[0] If $Sections[$X] = $SelectedStudent Then $Dates = IniReadSection($File, $Sections[$X]) If Not @error Then If $Dates[0][0] > 1 Then IniDelete($File, $Sections[$X]) For $y = 1 To $Dates[0][0] If $Dates[$y][1] <> $SelectedDate Then $Key += 1 IniWrite($File, $SelectedStudent, $Key, $Dates[$y][1]) ;MsgBox(0,"",$SelectedStudent & " " & $Y & " " & $Dates[$y][1]) GUICtrlSetData($DateList, _StringEncrypt(0, $Dates[$y][1], $HashKey)) Else ;$DeleteDStudent = $Key $StudentArray[$Key][0] = "" $StudentArray[$Key][1] = "" ;_ArrayInsert EndIf Next ExitLoop Else IniWriteSection($File, $SelectedStudent, "") EndIf GUICtrlSetData($TotalDaysMissed, GUICtrlRead($TotalDaysMissed) - 1) EndIf EndIf Next EndIf PopulateArray() SetWarningLevel() EndFunc ;==>Rosie #EndRegion ;**** Date Managment #Region ;**** Core/GUI Func PopulateArray() ;So hard...really. $TheMasterComplex = IniReadSectionNames($File) ;Read DB $AttendanceRecord[0][0] = 0 If Not @error Then ReDim $StudentArray[1][1] ReDim $AttendanceRecord[1][1] For $X = 1 To $TheMasterComplex[0] $DecryptedName = _StringEncrypt(0, $TheMasterComplex[$X], $HashKey) ;Decrypt Student names ReDim $StudentArray[UBound($StudentArray, 1) + 1][1] ;Resize student array ReDim $AttendanceRecord[UBound($AttendanceRecord, 1) + 1][2] ;Resize attendance array $StudentArray[$X][0] = $DecryptedName $StudentArray[0][0] = $X ;[0][0] = Total Number of students [x][0] = Name [x][1] = First Absent Date $AttendanceRecord[$X][0] = $DecryptedName ;_ArrayDisplay($AttendanceRecord) ;_ArrayDisplay($StudentArray) Next For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student If Not @error Then If $Dates[0][0] >= UBound($StudentArray, 2) - 1 Then ReDim $StudentArray[UBound($StudentArray, 1)][$Dates[0][0] + 1];UBound($StudentArray,2) + 1 For $Z = 1 To $Dates[0][0] $DecryptedDates = _StringEncrypt(0, $Dates[$Z][1], $HashKey) ;Decrypt first date $StudentArray[$X][$Z] = $DecryptedDates $AttendanceRecord[$X][1] = $Z ;$TotalD1 += 1 $StudentArray[0][1] += 1 ;Total Days missed Next If $Z > $AttendanceRecord[0][1] Then $AttendanceRecord[0][0] = $StudentArray[$X][0] ;Student name with the higest days absent $AttendanceRecord[0][1] = $Z - 1 ;Total Number of warnings ;MsgBox(0,"",$Z) ;MsgBox(0,"",$AttendanceRecord[$X][0]) EndIf EndIf Next ;_ArraySort($StudentArray) EndIf ;_ArrayDisplay($StudentArray) ;_ArrayDisplay($AttendanceRecord) _ArraySort($StudentArray, 0, 1) _ArraySort($AttendanceRecord, 0, 1) EndFunc ;==>PopulateArray Func PopGUI() ;PopulateArray() If $StudentArray[0][0] > 0 Then GUICtrlSetData($TotalDaysMissed, 0) GUICtrlSetData($StudentList, "") GUICtrlSetData($DateList, "") ;$Students = GUICtrlCreateListViewItem("",$StudentList) For $X = 1 To $StudentArray[0][0] ;GUICtrlSetData($Students, $StudentArray[$X][0]&"|"&$AttendanceRecord[$x][1]) $Students = GUICtrlCreateListViewItem( $StudentArray[$X][0]&"|"&$AttendanceRecord[$x][1],$StudentList) ;GUICtrlSetOnEvent($Students, "HandleClicks") Next Else PopulateArray() PopGUI() EndIf SetWarningLevel() ;_ArrayDisplay($StudentArray) EndFunc ;==>PopGUI Func HandleClicks() MsgBox(0,0, @GUI_CtrlID) EndFunc Func SetWarningLevel() $SelectedStudent = GUICtrlRead($StudentList) $Absent = GUICtrlRead($TotalDaysMissed) Select Case $Absent >= 10 TrayTip("", $SelectedStudent & " has been absent " & $Absent & " times!", 2) GUICtrlSetBkColor($DateList, 0xED1C24) MsgBox(0, "", "This student has been absent " & $Absent & " times!", 5) ;GUICtrlSetBkColor($TotalDaysMissed, 0xED1C24) Case $Absent >= 7 TrayTip("", $SelectedStudent & " has: " & $Absent & " warnings.", 1) GUICtrlSetBkColor($DateList, 0xED1C24);Red ;GUICtrlSetBkColor($TotalDaysMissed, 0xED1C24) Case $Absent >= 4 ;TrayTip("", $SelectedStudent & "has had :"&$Absent & " warnings.") GUICtrlSetBkColor($DateList, 0xFF8A15);Orange ;GUICtrlSetBkColor($TotalDaysMissed, 0xFF8A15) Case $Absent < 4 GUICtrlSetBkColor($DateList, 0x00FF00);Green ;GUICtrlSetBkColor($TotalDaysMissed, 0x00FF00) EndSelect EndFunc ;==>SetWarningLevel Func ViewTotals() _ArrayDisplay($AttendanceRecord) EndFunc ;==>ViewTotals Func ViewAll() ;_ArraySort($StudentArray) ;_ArraySort($AttendanceRecord) _ArrayDisplay($StudentArray) EndFunc ;==>ViewAll #EndRegion ;**** Core/GUI #Region ;**** Database Encryption **** Func Encrypt() $File = FileOpenDialog("Select database file to open:", "C:\Program Files\", "Decrypted .ini: (*.ini)", 1) If Not @error Then $Dir = FileOpenDialog("Save as...:", "C:\Program Files\", "Encrypted .ini: (*.ini)", 8) If Not @error Then $TheMasterComplex = IniReadSectionNames($File) If Not @error Then For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student $EncryptedName = _StringEncrypt(1, $TheMasterComplex[$X], $HashKey) ;Encrypt section names (aka Student names) ;IniWrite($Dir, $DecryptedName, "", "") For $Z = 1 To $Dates[0][0] $EncryptedDates = _StringEncrypt(1, $Dates[$Z][1], $HashKey) ;Encrypt first date IniWrite($Dir, $EncryptedName, $Z, $EncryptedDates) Next Next ShellExecute($Dir) EndIf EndIf EndIf EndFunc ;==>Encrypt Func Decrypt() $File = FileOpenDialog("Select database file to open:", "C:\Program Files\", "Encrypted .ini: (*.ini)", 1) $Dir = FileOpenDialog("Save as...:", "C:\Program Files\", "Decrypted .ini: (*.ini)", 8) $TheMasterComplex = IniReadSectionNames($File) If Not @error Then For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student $DecryptedName = _StringEncrypt(0, $TheMasterComplex[$X], $HashKey) ;Decrypt section names (aka Student names) ;IniWriteSection($Dir, $DecryptedName, "", "") For $Z = 1 To $Dates[0][0] $DecryptedDates = _StringEncrypt(0, $Dates[$Z][1], $HashKey) ;Decrypt first date IniWrite($Dir, $DecryptedName, $Z, $DecryptedDates) Next Next ToolTip("Decyrption Completed") ShellExecute($Dir) Sleep(750) ToolTip("") EndIf EndFunc ;==>Decrypt #EndRegion ;**** Database Encryption **** #cs Func AddDate() $SelectedStudent = GUICtrlRead($StudentList) If $SelectedStudent <> "" Then $hKey = _StringEncrypt(1, $SelectedStudent, $HashKey) ;Student name hashed $NewDatePlaintext = InputBox("New Date", "Please enter a new date", @YEAR & "\" & @MON & "\" & @MDAY);Default todays date If Not @error Then For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then ;MsgBox(0,"",UBound($StudentArray,2)) ;MsgBox(0,"",$StudentArray[$X][UBound($StudentArray,2)-1]) For $y = 1 To 11 If $StudentArray[$X][$y] = "" Then $StudentArray[$X][$y] = $NewDatePlaintext ;_ArrayDisplay($StudentArray) $Previousposts = IniReadSection($File, $hKey) If Not @error Then IniWrite($File, $hKey, $Previousposts[0][0] + 1, _StringEncrypt(1, $NewDatePlaintext, $HashKey)) Else IniWrite($File, $hKey, 1, _StringEncrypt(1, $NewDatePlaintext, $HashKey)) EndIf ExitLoop EndIf Next EndIf Next ;PopGUI() GUICtrlSetData($TotalDaysMissed, GUICtrlRead($TotalDaysMissed) + 1) GUICtrlSetData($DateList, $NewDatePlaintext) Else ToolTip("Canceled") Sleep(750) ToolTip("") EndIf Else MsgBox(0, "", "Please select a student first.") EndIf EndFunc ;==>AddDate Func NewStudent() $Name = InputBox("Name of Student.", "Type in name of student") If Not @error Then $Q = MsgBox(4, "", "Has the student been absent?") If $Q = 6 Then $Date = InputBox("Enter absent date.", "Type in the day the student was absent", @YEAR & "\" & @MON & "\" & @MDAY) If Not @error Then $EncryptedDate = _StringEncrypt(1, $Date, $HashKey) $EncryptedName = _StringEncrypt(1, $Name, $HashKey) $Write = IniWriteSection($File, $EncryptedName, "1=" & $EncryptedDate) GUICtrlSetData($DateList, $Date) GUICtrlSetData($StudentList, $Name) ;PopGUI() $TheMasterComplex = IniReadSectionNames($File) For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student If Not @error Then For $Z = 1 To $Dates[0][0] ReDim $StudentArray[$X][$Z] $DecryptedDates = _StringEncrypt(0, $Dates[$Z][1], $HashKey) ;Decrypt first date $StudentArray[$X][$Z] = $DecryptedDates Next EndIf Next EndIf Else $EncryptedName = _StringEncrypt(1, $Name, $HashKey) IniWriteSection($File, $EncryptedName, " ") ;PopGUI() EndIf EndIf EndFunc ;==>NewStudent Func PopGUI() $TheMasterComplex = IniReadSectionNames($File) ;Read DB If Not @error Then GUICtrlSetData($TotalDaysMissed, 0) GUICtrlSetData($StudentList, "") GUICtrlSetData($DateList, "") ReDim $StudentArray[1][1] For $X = 1 To $TheMasterComplex[0] $DecryptedName = _StringEncrypt(0, $TheMasterComplex[$X], $HashKey) ;Decrypt section names (aka Student names) GUICtrlSetData($StudentList, $DecryptedName) ReDim $StudentArray[UBound($StudentArray, 1) + 1][11] ;Resize student array $StudentArray[$X][0] = $DecryptedName $StudentArray[0][0] = $X ;[0][0] = Total Number of students Next For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student If Not @error Then For $Z = 1 To $Dates[0][0] ;ReDim $StudentArray[$X][$Z] $DecryptedDates = _StringEncrypt(0, $Dates[$Z][1], $HashKey) ;Decrypt first date $StudentArray[$X][$Z] = $DecryptedDates Next EndIf Next EndIf SetWarningLevel() ;_ArrayDisplay($StudentArray) EndFunc ;==>PopGUI Func RedrawDates() GUICtrlSetData($DateList, "") $TheMasterComplex = IniReadSectionNames($File) ;Read DB If Not @Error Then For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student If Not @error Then For $Z = 1 To $Dates[0][0] $StudentArray[$X][$Z] = $Dates[$Z][1] GUICtrlSetData($DateList,$DecryptedDates) Next EndIf Next EndIf EndFunc Func DeleteDate() $SelectedStudent = GUICtrlRead($StudentList) $SelectedDate = GUICtrlRead($DateList) ;$Q = MsgBox(4,"","Are you sure you want to delete:" & $SelectedDate) If $SelectedDate <> "" Then $hKey = _StringEncrypt(1, $SelectedDate, $HashKey) ;Student date hashed $hKey2 = _StringEncrypt(1, $SelectedStudent, $HashKey) ;Student name hashed For $X = 1 To $StudentArray[0][0] If $StudentArray[$X][0] = $SelectedStudent Then For $y = 1 To 11 If $StudentArray[$X][$y] = $SelectedDate Then ;ShellExecute($File) ;_ArrayDelete($StudentArray[$X],$y) $result = IniDelete($File, $hKey2, $y) ;MsgBox(0, "", "Result: " & $result) ;ShellExecute($File) $StudentArray[$X][$y] = "" ExitLoop EndIf Next EndIf Next PopGUI() ;GUICtrlSetData($TotalDaysMissed, GUICtrlRead($TotalDaysMissed) - 1) ;RedrawDates() Else MsgBox(0, "", "Please select a date", 3) EndIf EndFunc ;==>DeleteDate Func FixIni() $File = FileOpenDialog("Select database file to fix:", "C:\Program Files\", "Broken.ini: (*.ini)", 1) $Dir = FileOpenDialog("Save as...", "C:\Program Files\", "Fixed .ini: (*.ini)", 1) $Sections = IniReadSectionNames($File) If Not @error Then For $Fix = 1 To $Sections[0][0] IniWrite($File, $Sections[$Fix][1], $Fix, $Sections[$Fix][0]) Next EndIf EndFunc ;==>FixIni #ce Func PopulateArray2() $TheMasterComplex = IniReadSectionNames($File) ;Read DB $AttendanceRecord[0][0] = 0 If Not @error Then ReDim $StudentArray[1][1] ReDim $AttendanceRecord[1][1] For $X = 1 To $TheMasterComplex[0] $DecryptedName = _StringEncrypt(0, $TheMasterComplex[$X], $HashKey) ;Decrypt Student names ReDim $StudentArray[UBound($StudentArray, 1) + 1][1] ;Resize student array ReDim $AttendanceRecord[UBound($AttendanceRecord, 1) + 1][2] ;Resize attendance array $StudentArray[$X][0] = $DecryptedName $StudentArray[0][0] = $X ;[0][0] = Total Number of students [x][0] = Name [x][1] = First Absent Date $AttendanceRecord[$X][0] = $DecryptedName ;_ArrayDisplay($AttendanceRecord) ;_ArrayDisplay($StudentArray) Next For $X = 1 To $TheMasterComplex[0] $Dates = IniReadSection($File, $TheMasterComplex[$X]) ;Read dates for each student If Not @error Then If $Dates[0][0] >= UBound($StudentArray, 2) - 1 Then ReDim $StudentArray[UBound($StudentArray, 1)][$Dates[0][0] + 1];UBound($StudentArray,2) + 1 For $Z = 1 To $Dates[0][0] $DecryptedDates = _StringEncrypt(0, $Dates[$Z][1], $HashKey) ;Decrypt first date $StudentArray[$X][$Z] = $DecryptedDates $AttendanceRecord[$X][1] = $Z ;$TotalD1 += 1 $StudentArray[0][1] += 1 ;Total Days missed Next If $Z > $AttendanceRecord[0][1] Then $AttendanceRecord[0][0] = $StudentArray[$X][0] ;Student name with the higest days absent $AttendanceRecord[0][1] = $Z - 1 ;Total Number of warnings ;MsgBox(0,"",$Z) ;MsgBox(0,"",$AttendanceRecord[$X][0]) EndIf EndIf Next ;_ArraySort($StudentArray) EndIf ;_ArrayDisplay($StudentArray) ;_ArrayDisplay($AttendanceRecord) _ArraySort($StudentArray, 0, 1) _ArraySort($AttendanceRecord, 0, 1) EndFunc ;==>PopulateArray Note: I originally used a normal list, but was unable to "sort" the data how I wanted (it was always sorted alphabetically), so I decided to use a listview instead, and here I am. Oh and I know its such overkill to encrypt every string, I only found out about _Crypt_EncryptFile after I was halfway through this project T_T. Edited March 2, 2010 by BitByteBit Link to comment Share on other sites More sharing options...
Yoriz Posted March 3, 2010 Share Posted March 3, 2010 You need to store the handles in an array , not tested but like shown below local $hStudents[$StudentArray[0][0]] For $X = 1 To $StudentArray[0][0] $hStudents[$X] = GUICtrlCreateListViewItem( $StudentArray[$X][0]&"|"&$AttendanceRecord[$x][1],$StudentList) ;Here is my problem ;GUICtrlSetOnEvent($hStudents[$X], "HandleClicks") Next GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
BitByteBit Posted March 3, 2010 Author Share Posted March 3, 2010 (edited) Thanks for your reply, How do I poll for these in my while loop? Should I have a for to next within my while loop ? local $hStudents[$StudentArray[0][0]] For $X = 1 To $StudentArray[0][0] $hStudents[$X] = GUICtrlCreateListViewItem( $StudentArray[$X][0]&"|"&$AttendanceRecord[$x][1],$StudentList) ;Here is my problem ;GUICtrlSetOnEvent($hStudents[$X], "HandleClicks") Next While 1 $nMsg = GUIGetMsg() For $X = 1 to $StudentArray[0][0] If $nMsg = $hStudents[$X] then Msgbox(0,"","Do Something") ;Like this? Next Switch $nMsg Select Case $Students[???] ;Like this? Msgbox(0,"","Do Something") EndSelect WEnd Edited March 3, 2010 by BitByteBit Link to comment Share on other sites More sharing options...
Yoriz Posted March 3, 2010 Share Posted March 3, 2010 Take alook at this link for a better way of dealing with doubleclicks on listview items. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. 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