event handler questions

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
Clint
Posts: 3
Joined: Sat Dec 27, 2008 8:02 pm

event handler questions

Post by Clint » Sat Dec 27, 2008 8:15 pm

Hi

I'm a new Rev user, I've had media edition for about a week

For my first project, I've been trying to develop a form to convert distances

I want to be able to change kilometers to miles and miles into kilometers

I have a text entry field for the user to input a number, a push button to convert the number and a text field where I would like the result displayed

I'd like for the input to be a variable I can use in the event handler for the push button

ex. set it to dMiles

then have a formula for the conversion and output it in the second text box

I'd appreciate any pointers or example scripts

thanks

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Location: London, UK
Contact:

Post by Mark Smith » Sat Dec 27, 2008 10:07 pm

If you have a function like:

Code: Select all

function milesToKilometres tMiles
  return tMiles * 1.6
end milesToKilometres
then you can do this:

Code: Select all

on mouseUp
  put fld "miles" into tDistance
  put milesToKilometres(tDistance) into fld "kilometres"
end mouseUp
In fact, you don't need to put the miles field into a variable, you can do this:

Code: Select all

on mouseUp
  put milesToKilometres(fld "miles") into fld "kilometres"
end mouseUp
Hope this helps,

Mark

Clint
Posts: 3
Joined: Sat Dec 27, 2008 8:02 pm

got it working

Post by Clint » Sun Dec 28, 2008 3:46 am

Hi Mark

thanks so much for the help

I've got it working

next I'm going to try to create two more scripts, one to reset or clear the fields and one to close the form so, it will be two more buttons with mouseup handlers

best

Clint


[/img]

Clint
Posts: 3
Joined: Sat Dec 27, 2008 8:02 pm

code for event handlers

Post by Clint » Tue Jan 06, 2009 2:17 am

Hi all

I could use a few more pointers for my event handlers

what is the command to close or unload a form?
I have a button to Close

similarly, I'd be interested to learn the command to reset all the text boxes to blank based on a mouseup event

is there a good place in the dictionary or documentation to look for these sorts of commands, as I work on learning the syntax

thanks
Clint

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Tue Jan 06, 2009 7:11 am

Hi Clint,
what is the command to close or unload a form?
I have a button to Close
Set the script of your "Close" button to

Code: Select all

on mouseUp
  answer "Are you sure you want to close this form?" with "OK" or "Cancel"
  if it is "OK" then close this stack
end mouseUp
similarly, I'd be interested to learn the command to reset all the text boxes to blank based on a mouseup event
There is no such command, really - but it's pretty easy to roll your own reset routine, by adding something like this to your card script

Code: Select all

on preOpenCard
  ResetForm
end preOpenCard

command ResetForm
  put 0 into field "miles"
  put 0 into field "kilometres"
end ResetForm
The preOpenCard event will be sent to your card just before it is opened, allowing you to call your own 'ResetForm' command - which you can then reuse from a 'Reset' button, keeping the form reset code tidy and in a single spot.
is there a good place in the dictionary or documentation to look for these sorts of commands, as I work on learning the syntax
The tricky part about documentation is that it's never quite tailored to every person - some people are just starting out with programming in general, while others are coming in from Visual Basic or dabbled with Delphi in the past.
Your best bet is to go through the contents of the Revolution Resource Center (there's a button in the toolbar if you're running Revolution 3.0) and take it from there. And of course you're always welcome here to ask questions :-)

HTH,

Jan Schenkel
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Lynn P.
Posts: 79
Joined: Sun Apr 09, 2006 1:09 pm

Re: code for event handlers

Post by Lynn P. » Tue Jan 06, 2009 2:32 pm

Clint wrote: ...I'd be interested to learn the command to reset all the text boxes to blank based on a mouseup event
Hi Clint ~
I'd just add to Jan's excellent advise...
If you wish a field to be "blank" and have no text or numbers in it, you can also use the Rev constant "empty", for example:
put empty into field "miles"

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”