“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 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.

By |2018-11-01T17:22:09+00:00November 13th, 2014|Categories: Web Tips-n-Tricks|0 Comments

About the Author:

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 database solutions for Desktop, Mobile, and Web applications. Our core technology competencies are FileMaker Pro, FileMaker Go, and MySQL for database frameworks, along with FileMaker WebDirect, WordPress, MySQL, PHP, CodeIgniter, PostgreSQL, Joomla, Drupal, Magento and WooCommerce for websites and web applications. Aside from providing eXcellent customer service, our goals are to use these technologies to intuitively automate your organization’s data solution needs seamlessly and flawlessly across the web, mobile, and desktop platforms. Contact eXcelisys anytime for a free estimate and consultation about making your business more efficient through intuitive and effective software automation. 866-592-9235.

Leave A Comment

Website Content and Design

Website Content and Design

Copyright © eXcelisys, Inc., all rights reserved. No unauthorized use permitted; all derivative works must have prior approval. All content – including design and copy within the eXcelisys website is protected under international copyright laws. eXcelisys will prosecute ANYONE who borrows or steals any derivative or facsimile of the content and design of eXcelisys’ website without written approval or permission. Read More

Trademarks

Trademarks

FileMaker®, FileMaker Pro® and the referencing FileMaker® logos are trademarks of FileMaker, Inc., in the United States, the European Union and other countries. MySQL® and MySQL® Logos are registered trademarks of MySQL AB in the United States, the European Union and other countries. The PostgreSQL elephant logo “Slonik” is a registered trademark of the PostgreSQL Global Development Group. Read More

Privacy Policy

Privacy Policy

We will never give or sell your email address or contact information to anybody, for any reason. There are no eXceptions. We do not make our customer list available to anyone outside of eXcelisys at all, ever.

There is no way that submitting your information to eXcelisys will result in you receiving “spam” or other junk mail from eXcelisys if you have requested us not to do so. Read More