Page 1 of 1
event handler questions
Posted: Sat Dec 27, 2008 8:15 pm
by Clint
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
Posted: Sat Dec 27, 2008 10:07 pm
by Mark Smith
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
got it working
Posted: Sun Dec 28, 2008 3:46 am
by Clint
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]
code for event handlers
Posted: Tue Jan 06, 2009 2:17 am
by Clint
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
Posted: Tue Jan 06, 2009 7:11 am
by Janschenkel
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
Re: code for event handlers
Posted: Tue Jan 06, 2009 2:32 pm
by Lynn P.
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"