Spreadsheet to variables

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
SteveSpaw
Posts: 4
Joined: Thu Feb 27, 2014 5:32 pm

Spreadsheet to variables

Post by SteveSpaw » Thu Feb 27, 2014 5:52 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6791
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Spreadsheet to variables

Post by FourthWorld » Thu Feb 27, 2014 6:01 pm

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/
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

SteveSpaw
Posts: 4
Joined: Thu Feb 27, 2014 5:32 pm

Re: Spreadsheet to variables

Post by SteveSpaw » Thu Feb 27, 2014 7:14 pm

No problem I can easily export the xls as a csv. It is just text.

Is that easier?

Thanks,
Steve

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

Re: Spreadsheet to variables

Post by dunbarx » Thu Feb 27, 2014 7:16 pm

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

SteveSpaw
Posts: 4
Joined: Thu Feb 27, 2014 5:32 pm

Re: Spreadsheet to variables

Post by SteveSpaw » Thu Feb 27, 2014 9:54 pm

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

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: Spreadsheet to variables

Post by BvG » Fri Feb 28, 2014 1:17 am

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"
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

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

Re: Spreadsheet to variables

Post by dunbarx » Fri Feb 28, 2014 1:27 am

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Spreadsheet to variables

Post by Simon » Fri Feb 28, 2014 3:01 am

(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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6791
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Spreadsheet to variables

Post by FourthWorld » Fri Feb 28, 2014 3:51 am

If you have a choice, tab-delimited is much saner than CSV:
http://www.fourthworld.com/embassy/arti ... t-die.html
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

SteveSpaw
Posts: 4
Joined: Thu Feb 27, 2014 5:32 pm

Re: Spreadsheet to variables

Post by SteveSpaw » Fri Feb 28, 2014 4:18 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6791
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Spreadsheet to variables

Post by FourthWorld » Fri Feb 28, 2014 6:37 am

WARNING: The Surgeon General has determine that continued exposure to LiveCode can lead to addiction.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”