set dgData aborts script

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

set dgData aborts script

Post by okk » Sun May 16, 2021 4:35 pm

Hi,
I have a script that reads data from a file, then sets the dgData of my datagrid and then continues with other things. Now I noticed that when the data from my file is somehow corrupt my script quietly aborts when setting the dgData. How can I detect this error before the script abourts? I would like to display a warning like " your data is corrupt" and then continue with the rest of my script. How can I do this?

Here is my script:

Code: Select all

on readtreatment
   put tPATH & "/patientdata/TREATMENTS/" & patientID & ".txt" into tempfilepath
   if there is a file tempfilepath then
      put URL ("binfile:" & tempfilepath) into theEncodedArray
      decrypt theEncodedArray using "aes-256-cbc" with password globalpass and salt saltvalue
      if it is empty then
         -- beep
         exit readtreatment
      end if
      put it into theEncodedArray
      put arrayDecode(theEncodedArray) into tempdata
      set the dgData of group "treatmentlist" of card "treatment" to tempdata
   else
      set the dgData of group "treatmentlist" of card "treatment" to empty
   end if
end readtreatment
Thanks for any pointers!
Oliver

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: set dgData aborts script

Post by dunbarx » Sun May 16, 2021 4:43 pm

Hi.

Read up on the "try/catch" control structure in the dictionary. This is what it was made for.

Craig

okk
Posts: 176
Joined: Wed Feb 04, 2015 11:37 am

Re: set dgData aborts script

Post by okk » Mon May 17, 2021 7:41 am

Thanks! That's what I was looking for. I somehow have hard times finding stuff in the dictionary which I don't know yet. In any case, when I set the dgData of my datagrid with the corrupt data I catch the following error-message:

Code: Select all

69,4381,17
77,4381,29
456,4381,17
465,4381,17
490,4381,17
490,4381,17
253,4381,17
241,4333,1,_table.DrawColumns
353,0,0,stack "/Users/oliver/Applications/LiveCode Indy 9.6.2 (rc 5).app/Contents/Tools/Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript"
573,4277,1,_table.DrawColumns
253,4277,1
253,4277,1
241,4274,1,_table.DrawControlsInRealTime
353,0,0,stack "/Users/oliver/Applications/LiveCode Indy 9.6.2 (rc 5).app/Contents/Tools/Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript"
573,3942,1,_table.DrawControlsInRealTime
241,3942,1,_table.DrawWithProperties
353,0,0,stack "/Users/oliver/Applications/LiveCode Indy 9.6.2 (rc 5).app/Contents/Tools/Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript"
573,2618,1,_table.DrawWithProperties
587,2618,1
241,2616,1,_DrawListWithProperties
353,0,0,stack "/Users/oliver/Applications/LiveCode Indy 9.6.2 (rc 5).app/Contents/Tools/Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript"
573,1934,1,_DrawListWithProperties
253,1934,1
241,1933,1,_DrawList
353,0,0,stack "/Users/oliver/Applications/LiveCode Indy 9.6.2 (rc 5).app/Contents/Tools/Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript"
573,5319,1,_DrawList
241,5319,1,dgData
353,0,0,stack "/Users/oliver/Applications/LiveCode Indy 9.6.2 (rc 5).app/Contents/Tools/Toolset/palettes/revdatagridlibrary/behaviorsdatagridbuttonbehavior.livecodescript"
449,191,10
535,191,1
How can I see what is the actual error here?
Thanks!
oliver

stam
Posts: 2635
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: set dgData aborts script

Post by stam » Mon May 17, 2021 11:58 am

okk wrote:
Sun May 16, 2021 4:35 pm
Hi,
I have a script that reads data from a file, then sets the dgData of my datagrid and then continues with other things. Now I noticed that when the data from my file is somehow corrupt my script quietly aborts when setting the dgData. How can I detect this error before the script abourts? I would like to display a warning like " your data is corrupt" and then continue with the rest of my script. How can I do this?
Hi Oliver
I personally always look at the data i'm trying to import by setting a breakpoint immediately before the import and stepping through it. I often find and correct the issue there, as it's often something silly i've done...

Usually it's because i've made the assumption the data i'm trying to set the data grid's dgData is correctly formatted and it's not.
Remember, this should be a numerically keyed array in the format:

Code: Select all

[Array]
   [1][key1][key2]...[keyX]
   [2][key1][key2]...[keyX]
   ...
   [n][key1][key2]...[keyX]
if not formatted that way, the data grid can misbehave or not display data. I also make sure that the key name matches the variable name in the fillIn handler of the row prototype (if using a form) or the column name (not label) if using a table.

Another useful thing to do is examine what's actually in the dgData - you can do this by browsing the data grid's custom properties -> in the drop down menu select dgCache and it will show you what you've set the dgData to...

Hope this helps,
Stam
Last edited by stam on Mon May 17, 2021 2:51 pm, edited 1 time in total.

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: set dgData aborts script

Post by Mikey » Mon May 17, 2021 2:46 pm

catch takes a parameter:
catch theMessage
theMessage contains the error

Alternatively, I'd be interested in seeing what's happening because it might be an interesting deep dive into the dg code to address the problem so that it doesn't happen to begin with.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”