“Learn from the master, you must!”

If you do any development outside of FileMaker Pro (and trust me, if only to learn different ways of approaching problems, you really should), you know that there’s a “gotcha” when assigning and using variables.

In several languages, you can assign a FileMaker variable like this:

$myvariable = ‘my value';

Simple enough. But then when you want to test the variable, you can’t use “=” again, because that would just reassign it. So if, for example, you did this:

if ($myvariable = ‘something else’) {
everyoneDies();
}

… everyone would die … because you didn’t really test it – you just reassigned it. If the variable name comes first, “=” is an assignment operator. So in the example above, since you’re assigning a new value to $myvariable, and that will always work, the test will always return true. The test for equality, which is what you want here, is “==” – two equals signs (if you wanted to test for both type and content, you’d use three [“===”], but that’s only for really picky languages). So what that should have said was…

f ($myvariable == ‘something else’) {
everyoneDies();
}

… so everyone would live, because your original value of “my value” remains intact, and is not equal to “something else” – we’re all safe!

Unfortunately, every developer (yes, EVERY developer) has forgotten that second equals sign at least once. The fortunate among us have discovered that before the client demo. Those not so fortunate…well…please remember to give to charity.

There is, however, some Jedi magic we can use here. If we use “Yoda syntax,” we can avoid this mistake altogether. Consider this:

If (‘something else’ = $myvariable) {
everyoneDies();
}

In this case, we put the value first. Most language interpreters are smart enough to see that. So they will treat the single equals sign as an equality operator and not an assignment operator, and the test will be evaluated as intended. Everyone lives!!

May the force be with you.

About Excelisys, Inc.: Founded in 2001, Excelisys (www.excelisys.com) is an FBA Platinum Partner and FileMaker Certified developer organization. Excelisys specializes in designing, developing, customizing, supporting, consulting, migrating, upgrading, fixing, and integrating of FileMaker Pro and FileMaker Go database solutions, MySQL, PHP, CodeIgniter, PostgreSQL, QuickBooks-FileMaker Pro Integration, Excel and MS Access to FileMaker Pro conversions/migrations, iPhone and iPad business solutions, and other various database frameworks and web technologies that automate your organization’s data solution needs for use on the web, mobile, and desktop platforms. Contact Excelisys today for a free estimate and consultation about your business software automation needs @ 866-592-9235.