Page 1 of 1

Spreadsheet to variables

Posted: Thu Feb 27, 2014 5:52 pm
by SteveSpaw
OK I am a real NOOB but I have taken several examples from other projects and built a pretty neat tool. (This LiveCode makes me feel like a genius ) But Now I need something new and wonder if it is over my head right now.
My client gives me a spreadsheet of name,title,number,other in columns.
I need to read each of these in one row at a time into 4 variables, display them, wait for next cue and call up the next row.
Rinse and repeat several hundred times for a presentation.

How hard is this?
I would be happy to send out some beer money for help :D

Thanks,
Steve

Re: Spreadsheet to variables

Posted: Thu Feb 27, 2014 6:01 pm
by FourthWorld
Excel is a complex, proprietary format. If your client could send you a tab-delimited export from the spreadsheet, it would be very easy to work with that data in LiveCode (see the itemDelimiter property in the Dictionary).

If you must work with Excel's format, you may want to consider relying on others who've already done the heavy lifting on parsing it - there's a library for this in the LiveCode store:
http://livecode.com/store/marketplace/excel-library/

Re: Spreadsheet to variables

Posted: Thu Feb 27, 2014 7:14 pm
by SteveSpaw
No problem I can easily export the xls as a csv. It is just text.

Is that easier?

Thanks,
Steve

Re: Spreadsheet to variables

Posted: Thu Feb 27, 2014 7:16 pm
by dunbarx
Hi.

What Richard said.

If you are well on you way to learning LC, does this help?:

Code: Select all

set the itemDelimiter to tab
repeat with y = 1 to the number of lines of yourData
put item 1 of line y of yourData into tname
put item 2 of line y of yourData into tTitle
put item 3 of line y of yourData into tNumber
put item 4 of line y of yourData into tOther
 put tName & return & ttitle & return & tNumber & return & tOther into fld "display"

cueThingHere --see below

end repeat

What do you mean by "wait for the next cue"? Is it a mouseClick? Is it a keypress? If a mouseClick, you can just:

wait until the mouseClick

If a keypress:

wait until the optionKey is down --or whatever

Waiting is blocking, but in this project that does not seem to matter. Or does it? Do you know what "blocking" means?

Craig Newman

Re: Spreadsheet to variables

Posted: Thu Feb 27, 2014 9:54 pm
by SteveSpaw
OK I think I get want you have.
Yes I would have a button to advance to the next line.
still noob questions-
How do I get the CSV into this script? I have not done anything with external files yet.
what if I wanted a + and - type of function to go through the data up and down. I would do some math on the y number?

Thanks a lot, I just jumped into this and am doing some more of the tutorials now, I just could stop myself from making something. Now I am building something that I can use.

Steve

Re: Spreadsheet to variables

Posted: Fri Feb 28, 2014 1:17 am
by BvG
SteveSpaw wrote:How do I get the CSV into this script?

Code: Select all

on mouseUp
   answer file "select the CSV file"
   if it = "" then
      exit mouseUp
   else
      put url ("file:" & it) into yourData
   end if
   --do something with 'yourData' here!
end mouseUp
don't forget to look in the dictionary for the relevant terms like "mouseUp", "exit", "answer file", "file:" as well as "url"

Re: Spreadsheet to variables

Posted: Fri Feb 28, 2014 1:27 am
by dunbarx
Hi..

Many different ways, just go get it. One way, look up the "answer file" command in the dictionary. It would go something like:

Code: Select all

on mouseup
   answer file" Which File?"
   put it into tFile
   open file tFile 
   read from file tFile until EOF
close file tFile
answer it
end mouseup
If you want to have some sort of interaction as you mentioned with your data once you download it, I think you should place it into, say, a table field, and use standard tools from there. It would be possible to do this in a running handler, but it would be more robust to deal with a field full of data. Less juggling and more easily maintained.

So, how are you going to go about all this? Write back at any time with problems, less so with requests for solutions. We have infinite patience for the former. Build, practice, fail, triumph. That is how you must learn to program.

Craig

Re: Spreadsheet to variables

Posted: Fri Feb 28, 2014 3:01 am
by Simon
(This LiveCode makes me feel like a genius )
By the end of next week you'll be feeling like a god!

Working with .cvs and liveCode is an awesome combination.

Simon

Re: Spreadsheet to variables

Posted: Fri Feb 28, 2014 3:51 am
by FourthWorld
If you have a choice, tab-delimited is much saner than CSV:
http://www.fourthworld.com/embassy/arti ... t-die.html

Re: Spreadsheet to variables

Posted: Fri Feb 28, 2014 4:18 am
by SteveSpaw
Wow I hate you guys! :-) I only got 2 hours of sleep last night working on this and NOW with this great info - I can't get away. It is a tractor beam.

Thanks a lot !!!!
Very helpful info.

Steve

Re: Spreadsheet to variables

Posted: Fri Feb 28, 2014 6:37 am
by FourthWorld
WARNING: The Surgeon General has determine that continued exposure to LiveCode can lead to addiction.