questions -- beginning to work with data grids

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
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

questions -- beginning to work with data grids

Post by ittarter » Wed Sep 02, 2015 2:26 pm

Hi!

I have a lot of tab delimited data and I've been using tables to display this data on my card.

A few questions:

1. I get an error "chunk: cannot find background" with the last line of the following code
set the itemdel to tab
...
repeat until tCurrentLine > tUpperLimit
put line tCurrentLine of URL("file:" & gName & ".txt") & return into line tCurrentTableLine of tText
add 1 to line tCurrentLine
add 1 to line tCurrentTableLine
end repeat
set the dgText of group "Data Grid" to tText
Is this because I don't have a key set up for each line, or for some other reason?

2. I read in Livecode Lessons that data grids can only operate with keys. Since I don't want to store the keys permanently in the file, could I simply put an ascending integer as the first item of each line I'm preparing to send to the data grid, and then make that column invisible?

3. Basic tables can be edited directly by the user. Is this also true of data grids? If a user were to click on a table cell, it automatically becomes editable, but with data grids this doesn't happen. Then, if a user hits the return key, tabs to the next cell, mouse-clicks another cell or mouse-clicks outside the data grid, how can I indicate to the application that it's time to verify the integrity of the new data and to then update the URL? (I don't even know how to do that last bit with basic tables.)

Thanks for all your help.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: questions -- beginning to work with data grids

Post by dunbarx » Wed Sep 02, 2015 3:44 pm

Hi.

Something is wrong. If you do something silly, like:

Code: Select all

   set the dgtext of grp "dg1" to "ABC" & tab & "XYZ"
You will populate that DG. Of course, watch the name of the group. And of course, in your own handler, make sure that the variable tText actually contains some text.

DataGrids store their data internally as arrays. But this data may be transformed into the clear at any time using the "dgText", as you seem already to know. I do not know what you mean by
data grids can only operate with keys
DataGrids also allow direct cell editing. This is a property (allow editing) that is true by default when you create one. Is it possible that property is "false"?

Craig Newman

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: questions -- beginning to work with data grids

Post by Klaus » Wed Sep 02, 2015 4:04 pm

Hi ittarter,
ittarter wrote:...
1. I get an error "chunk: cannot find background" with the last line of the following code
this means that you do NOT have a group (Datagrid) named "Data Grid" on the current card! 8)

Code: Select all

set the itemdel to tab
...
repeat until tCurrentLine > tUpperLimit
   put line tCurrentLine of URL("file:" & gName & ".txt") & return into line tCurrentTableLine of tText
   add 1 to line tCurrentLine
   add 1 to line tCurrentTableLine
end repeat
set the dgText of group "Data Grid" to tText
Ouch! :D
1. you are accessing the complete file in each reapet loop!
Not very effective and will slow down the script.

2. No idea what "tUpperlimit" is, but this is a lot more effective, as you will agree!
No repeat loop, no counters to be managed and a ONE-LINER :D

Code: Select all

...
put tUpperlimit -1 into tMax
set the dgtext of grp "your REAL datagrid group name here" to line 1 to tMax of url("file:" & gName & ".txt")
...
If tUpperLimit = the number of lines in that file you can even:

Code: Select all

...
set the dgtext of grp "your REAL datagrid group name here" to url("file:" & gName & ".txt")
...
HINT:
Load the DataGrid docs here as a PDF file and work through it at least 50 times*** :D
http://lessons.runrev.com/m/datagrid

***That's what I did and do so whenever I start a new project with datagrids involved!
DataGrids ARE the most complicated and complex objects in Livecode!


Best

Klaus

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: questions -- beginning to work with data grids

Post by ittarter » Wed Sep 02, 2015 4:12 pm

Never mind, there was a space in front of the group name so it was " week" instead of "week" :lol:

Ah, editing requires double-clicking. :roll: :roll: :roll:

EDIT. OK, Klaus, I don't know about 50 times, but I'll keep working through it until my program works. Thanks.
Last edited by ittarter on Wed Sep 02, 2015 4:24 pm, edited 2 times in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: questions -- beginning to work with data grids

Post by Klaus » Wed Sep 02, 2015 4:20 pm

ittarter wrote:OK, Klaus, I don't know about 50 times, but I'll keep working through it until my program works. Thanks.
That was of course just a joke, but with a true core! :D

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: questions -- beginning to work with data grids

Post by ittarter » Wed Sep 02, 2015 4:25 pm

Joke received and accepted. :D

Hey, can you explain that faster-better-shorter code you gave me? The only new keyword I see in operation is "to", and I have no idea what the -1 does after the variable.......

I use A LOT of repeats in my code, many of which access URLs each time. So I REALLY want to understand this.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: questions -- beginning to work with data grids

Post by Klaus » Wed Sep 02, 2015 4:33 pm

OK, but first tell me what "tUpperLimit" is exactly :D

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: questions -- beginning to work with data grids

Post by ittarter » Wed Sep 02, 2015 10:21 pm

Klaus wrote:OK, but first tell me what "tUpperLimit" is exactly :D
Basically I have a data file of multiple parts and each part is headed by a bracketed title. If my program is currently interested in, for example, the journal, I use the lineoffset function to mark the starting line of the section, go line by line through the text, and "repeat until" the program finds another bracketed title.

With the tUpperLimit, I was searching the "journal" section for a specific week of entries, with the week starting on a Monday. So the program would display entries from 8/24 to 8/30. I would find each Monday by converting the date (item 2) to its long form, then set one as the upper limit and the next Monday as the lower limit. The program would run from the upper to the lower limits and display the text between them.

So, how would you do it? :wink: :wink:
Last edited by ittarter on Thu Sep 03, 2015 4:21 pm, edited 1 time in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: questions -- beginning to work with data grids

Post by Klaus » Thu Sep 03, 2015 1:09 pm

Hm, this is a COMPLETELY different problem than your initial repeat loop! 8)

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: questions -- beginning to work with data grids

Post by ittarter » Thu Sep 03, 2015 4:21 pm

OK, never mind then :)

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: questions -- beginning to work with data grids

Post by Klaus » Thu Sep 03, 2015 4:35 pm

Well, I wanted to take a look when I find the time, but nothing more to look at now... :D

Post Reply