Recalculate on variable change

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
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Recalculate on variable change

Post by RossG » Sat Dec 03, 2016 11:46 pm

I have a variable which the user can change in a
drop-down list. A change of this variable will
trigger a re-calculation of data.

Can I have code which will start this re-calculation
when the user changes the variable (after a suitable
warning)?

I could use an ask dialogue if I could attach code to
one of the buttons (i.e "OK") else would need the
user to click another button. Would work but not
so "elegant" I feel.

While on the subject of the "ask" dialogue window
is there any way to change the size (in Win) or any
of the other parameters of said window?

I see elsewhere that the "ask" function is regarded
as being out-of-date. What's the best alternative?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

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

Re: Recalculate on variable change

Post by dunbarx » Sun Dec 04, 2016 1:17 am

Any clever and fun choosing method will do. A drop down menu that magically appears when you click on the "Press Me" button? A scrolling list field?

Since you are changing a variable from the outside, may I assume this is a global?

In any case. Once you have your selection, you (pseudo)

Code: Select all

global gVar
  on menuPick pItemName
  put pItemName into gVar --if a pull down or similar button
  ---------
  put the selectedText into gVar --for a list field, say
  ---------
  doWhatEverElseMightBeAppropriateForTheMethodYouChose --for whatever

  
Or is any of this related to your problem?

Craig Newman

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Recalculate on variable change

Post by richmond62 » Sun Dec 04, 2016 1:00 pm

Here's a thought:

on menuPick chooseNum
put chooseNum into CHNUM
answer "Do you want to recalculate with the new number?" with "Yes" and "No"
if it is "Yes" then
put ((CHNUM * 3) + 27) into fld "xyz"
end if
end menuPick
NC.png
Number Cruncher.livecode.zip
Here's the stack.
(1.2 KiB) Downloaded 168 times
Needless to say, if you want the menuPick to access a script outwith itself you will
need to put the chosen number into a global you have previously declared, and then
where my script has "put ((CHNUM * 3) + 27) into fld "xyz" " you will have to have something
like:

send "mouseUp" to button "Do It Baby"

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”