« Servoy 3.5 New Features Tutorial | Main | [Article] Getting data from Filemaker to Servoy »
May 22, 2007
[Tip] Shortcut for the opposite
by David Workman
Data Mosaic
There are a number of element properties that are either true or false. Enabled, transparent, & visible come to mind. Quite often you will find yourself toggling these element properties:
if (elements.btn_push.visible) {
elements.btn_push.visible = false
}
else {
elements.btn_push.visible = true
}
The following line is a shortcut for the above code:
elements.btn_push.visible = !elements.btn_push.visible
This trick also works with global boolean type variables. You set a global variable to boolean type by designating it as a media type. You can then assign that variable a true or false value in a method:
globals.myBoolean = true
To set it to the opposite value then:
globals.myBoolean = !globals.myBoolean
Same goes for variables defined in methods:
var x = true
application.output(x = !x)
| Posted by David Workman on May 22, 2007 at 06:54 PM in Tips | Permalink