Page 1 of 1

Spreadsheet like calculations

Posted: Tue Sep 17, 2013 10:53 am
by alexransome
Hi,

I have started to learn Livecode and am getting real excited about it, but I feel that I need to have a project I can think about developing whilst I learn Livecode.

I have an idea for an app which is like a spreadsheet in that it has text boxes for cells and like a spreadsheet some text boxes will have text that the user has entered and some will display a result based on a calculation that uses a text box or uses a fixed value, or may even use a figure derived from the internet (but that will be later on).

Can Livecode handle this sort of thing, I'm sure it can but where will I need to be looking?

Thanks for any responses.

Re: Spreadsheet like calculations

Posted: Tue Sep 17, 2013 1:57 pm
by dunbarx
Welcome to paradise.

LC can certainly handle this, and it is the best possible way to learn. In fact, your project is ambitious. I usually recommend an address book or calculator. LC could create a stack that works exactly like Excel, but why reinvent the wheel?

That said, you will need to learn about messages and how they are generated and trapped. You may be familiar with how a "mouseUp" message is generated when you click on an object like a button, and that is pretty easy to grasp. You will now need to consider how clicking in a field, changing the contents of that field, exiting that field, and other actions also generate messages that need to be trapped and handled.

Look up the "textChanged", "openField, "closeField", "keyDown", 'ReturnInField" and "tabKey" messages. Also the "clickText" function and its relatives. Also look up all the "see also" suggestions in each of those. Oh, and there are many other related language elements that will be useful for you.

Write back when you get stuck. The community here races to answer your questions.

Craig Newman

Re: Spreadsheet like calculations

Posted: Tue Sep 17, 2013 6:08 pm
by alexransome
Thanks for the reply.

I'm not wanting to remake excel. Just replicate these two formulas ...

=sum(((C7+C3-(C4+C5))/C1))*100

=sum((C3-(C4+C5))/D2)

Cheers.

Re: Spreadsheet like calculations

Posted: Tue Sep 17, 2013 6:28 pm
by Simon
Hi alexransome,
This is easy in liveCode.
To keep things simple name your fields the same as your cells:

Code: Select all

on mouseUp
   answer (((field "C7"+ field "C3"-(field "C4"+ field "C5"))/ field "C1"))*100
end mouseUp
That should do it :)

Simon

Re: Spreadsheet like calculations

Posted: Tue Sep 17, 2013 6:47 pm
by Klaus
Hi Alex,

no need to even reinvent the wheel in Livecode, look at this fine and free library:
http://www.tapirsoft.com/#!rgrid/mainPage :D

And check the rest of the website, too!


Best

Klaus