I am now working on the part that creates all the events for a day.
This is the code that adds my values to an array and sorts it based on the time the event is to be broadcasted on our PA.
Code: Select all
on mouseUp
local thisButton, tSortedArra, tNextIndex
put the short name of the target into thisButton
switch thisButton
case "add_btn"
put empty into tempArray
put the label of button "uren_btn" into tempUur
put the label of button "minuten_btn" into tempMinuut
put the label of button "boodschappen_btn" into tempBoodschap
put tempUur & ":" & tempMinuut into tempTijd
put the number of lines of (the keys of gBoodschappenArray) into arrayLengte
put tempTijd &TAB&tempBoodschap&TAB&"1" into gBoodschappenArray[arrayLengte+1]
//sorteren nu
get the keys of gBoodschappenArray
sort lines of it by gBoodschappenArray[each]
split it by return
# create a new sorted array using the mapped keys
put 1 into tNextIndex
repeat for each element tIndex in it
put gBoodschappenArray[tIndex] into tSortedArray[tNextIndex]
add 1 to tNextIndex
end repeat
put tSortedArray into gBoodschappenArray
VulDataGrid
break
end switch
end mouseUp
Code: Select all
on VulDataGrid
//dispatch "ResetList" to group tempDGName
//nu naar datagrid
put "DataGrid 1" into tempDGName
//set the dgData of group tempDGName to empty
put false into firstLineContainsHeaders
put the number of lines in the keys of gBoodschappenArray into hoeveelBoodschappen
repeat with i = 1 to hoeveelBoodschappen
put gBoodschappenArray[i] into pText
if i = 1 then
set the dgText [firstLineContainsHeaders] of group tempDGName to pText
else
put the dgNumberOfLines of me + 1 into theLineNo
put gBoodschappenArray[i] into tempList
split tempList using TAB
put tempList&"i"&i
put tempList[1] into tempArray["Tijd"]
put tempList[2] into tempArray["boodschap"]
put tempList[3] into tempArray["Aanpassen"]
dispatch "AddData" to group tempDGName with tempArray, theLineNo
set the dgProps["sort by column"] of group tempDGName to "Tijd"
end if
end repeat
end VulDataGrid
However... The events of a day (there are different types of 'days' for the PA, depending on schooldays, weekends, holidays, ...) can change, so need to be able to be adapted, or, you know, you can just make a mistake and have an event deleted. No problem, I have inserted buttons in my rowtemplate of the datagrid, and I know which line needs to be deleted. (This was the reason why I work with my own array and have that put into the datagrid. Just use the array from the dataGrid itself gave me trouble because the keys weren't renumbered.)
So this is the code that does just that.
Code: Select all
on DGbutton
switch DGKnop
case "audio_btn"
break
case "edit_btn"
//set the icon of button"edit_btn"of me to "edit_up"
break
case "wis_btn"
delete variable gBoodschappenArray[DGLijn]
put 0 into tCounter
repeat for each key tKey in gBoodschappenArray
add 1 to tCounter
put gBoodschappenArray[tkey] into tTaskListTemp[tcounter]
end repeat
put tTaskListTemp into gBoodschappenArray
VulDataGrid
break
end switch
end DGbutton
I notice that after a while of deleting the first entry, and adding again, pressing one of my buttons in the template causes the wrong line to be highlighted in the datagrid however. So this is probably why the datagrid crashes when I delete another line than the first one, I delete a key that doesn't exist. But I don't get it why it does this.
I am at my wits end...