Log in
Hot & Trending on FMT

Gotcha’s When Assigning and Using Variables

Featured Gotcha’s When Assigning and Using Variables

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 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’) {

…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’) {

…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) {

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 Andy Frazier: Andy, a Lead FileMaker Pro and Web Developer with Excelisys for 2 years, wrote his first program in BASIC on a Commodore 64 back in the early 80’s. So, having successfully conquered computers for all time, he took a break from them for about 20 years, playing guitar and writing music (his degree from Berklee is in Film Scoring; he’s written scores for video games and had songs in TV shows like The Sopranos & Charmed). When it turned out there just might be something more to this whole computer thing, he discovered FileMaker Pro, and realized not only that it was easy, it was fun, and it could make a difference by making many people’s jobs much easier. Now certified for FileMaker versions 8 through 13, along with Javascript, PHP, and jQuery, his goal is to create new solutions to improve someone’s life, somehow, some way, every day. Andy was the original developer for a very successful suite of solutions (which can’t be disclosed or he would have to kill himself) in the retail and service industries, he is also the author of several PHP-focused articles, and “the fixer” for countless issues ranging from overhauling failing businesses to solving sticky script situations. Andy has one philosophy with regard to thinking outside the box: there is no box. He feels the best part of developing with a tool like FileMaker Pro is using all the complimentary related technologies (PHP, XML, ODBC, CSS, HTML, Javascript) to do what each is best at and combining them into a whole complete-finished and polished solution which is more than the sum of its parts. 

About Excelisys, Inc.: Founded in 2001, Excelisys (www.excelisys.com) is a dedicated organization specializing in the designing, developing, customizing, supporting, consulting, migrating, upgrading, tweaking, fixing, and integrating of FileMaker Pro solutions, FileMaker Go solutions, MySQL, PostgreSQL, QuickBooks-FileMaker Pro Integration, Excel and MS Access FileMaker Pro conversions/migrations, iPhone and iPad business solutions, and other various database technologies and frameworks 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.

* FileMaker and FileMaker Pro are registered trademarks and owned by FileMaker, Inc. in the US and other countries.


Read more or have Excelisys make your FileMaker Solutions Better


We’ve assembled a team of brilliant developers creative problem solvers and consummate professionals, workhorses and web wizards, who work tirelessly to provide you with the best custom solutions to your data management needs. If you’re looking for spineless, Fritos-munching, Mountain-Dew-drinking, living-in-mommy’s-basement, tunnel-visioned order-takers, you won’t find them at Excelisys. We only hire the best.

And you should too.

Our team brings more than 200 years of combined experience in custom database development and management to bear on your solutions. In developer years, just like in dog years, that’s closer to 1,400 years. And 1,400 years ago the Byzantine Empire still existed. Think about it.

We’ve worked with everyone under the sun-from Adobe, the Ayn Rand Foundation, Chevron and Cisco Systems to the University of Chicago, Yoga Journal and Zenith Travel-and they all love us. We know you’re probably thinking, “Those are all huge companies with truckloads of money.” Don’t worry about that; from our perspective, no job is too small! In fact, size really doesn’t matter to us. And unlike most people who say it, we really mean it. Just ask Ted Cheeseman, CEO of Cheeseman’s Ecology Safaris, or Neil King, President of King Shots, Inc., or Todd Golebiewski, Manager of River View Campground & Canoe Livery. You can even call them. Just check our references section and you’ll find their numbers there.

We’ve received the most feedback and some of the highest scores on FindFileMakerDevelopers.com, the data management world’s Service Magic-esque client feedback interface. See what our clients are saying: http://filemakertoday.com/filemaker-integration/item/excelisys?category_id=20.

Call us geeks, but we love solving database management problems. Seriously. And our love for what we do shows in the solutions we provide to our clients. And our solutions make our clients love us back. In fact, we have a 95 percent client retention rate. They just keep coming back for more.

Website: www.excelisys.com