datagrid crashes (I think)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Johan_VH
Posts: 67
Joined: Fri Mar 28, 2014 2:46 pm

datagrid crashes (I think)

Post by Johan_VH » Tue Dec 09, 2014 5:23 pm

I am making a PA (public announcement) for the museum where I work. I did this years ago in Director, but since modifications were needed I am switching everything to LC.

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
Works fine, the array is ok, and is then added to the datagrid with this code. (the line "dispatch "ResetList" to group tempDGName" was one of my attempts to get it fixed)

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
When this code is executed, it works just fine, the datagrid is updated and I'm a happy coder.

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
And that is where the trouble begins. As soon as I delete a key from the array and have it renumbered, the datagrid somehow crashes. Whenever I get to a line of code that tries to do something with the datagrid like "dispatch "ResetList" to group tempDGName" or " set the dgText [firstLineContainsHeaders] of group tempDGName to pText" it just stops executing the code. I can add to my array as much as I want after that, it doesn't display it in the datagrid anymore simply because it fails to execute the code. I do not get an error. When I just delete the first line from my array, it works fine however. It doesn't display in the datagrid, but as soon as I add another event it executes the code again and the datagrid displays correctly. If I attempt to delete any other line, it fails again and although I can see the array being updated just fine, the datagrid refuses.

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”