Troubleshooting Programming Statements Q&A's programming facilities are easy to use. You can quickly develop simple and effective solutions to most of your application needs. However, sometimes, your programming may be more complex or the simple statements you are using may not be behaving the way you think they should. These tips may help you see what's going wrong and get you on your way again. Take short steps. Verify that simple statements are working correctly, before combining them to produce more complicated statements. For example, if you are manipulating data from a LOOKUP function, begin by just bringing the data into your database. When you have that part working securely, add the calculations you want to perform. Use extra fields. While testing your programming, use extra fields to store and display intermediate results. When the pieces work separately, combine them and eliminate the extra fields. Step through your form. When you begin the programming in a field with a < or a > (greater and less than signs), Q&A executes the statements as the cursor enters or leaves the field. (See F-167 in your manual for more information.) You can take advantage of this feature to have Q&A calculate each field, one at a time, as you move through the database. In this way you can examine the effects of each field's programming statements, in isolation from all the other fields. Check format values. If the form seems to be ignoring data that you know is being sent to the field, check the field's format value. Text in a number field becomes 0; inappropriate information in date or time fields become blanks. LOOKUPs use text. The key field and column in LOOKUP statements and the primary key field and external key field in XLOOKUP statements are all treated as text, for the purpose of finding matching entries. The information returned by the statements is also text. Q & A Application Note Rev. 6/92 #2111 Page 1 of 2 Troubleshooting Programming Statements Copy parts that work. Once you have a programming statement working, you may need a minor variation on the statement in another field. For example, you might use a group of XLOOKUP commands to get information from several fields in an external database. Although, Q&A is unable to copy programming from one field to another, you could define a macro to produce the repeated portion of the statement in as many fields as needed. Watch for order of calculation. Pay attention to when fields are calculated. Calculations with F8 and automatic calculations are done in order of the field number used on the Program Spec. Fields with < or > at the beginning of their programming statement calculate only when the field is tabbed through, and not with F8 or Automatic calc. Note that if you back into or out of a field (via , for example) programming statements that begin with < or > are not performed. For example, your statements might include: Total Cost: #20 = @SUM(#1..#10) * #30 Discount: #30: IF #20 > 100 THEN #30 = .9 ELSE #30 = 1 If you use Automatic or Manual calc, the Total Cost field may not be filled accurately. This is because #30 is an element in the calculations for Total Cost, but #30 gets calculated after Total Cost has already been filled in. The following construction avoids the problem: Total Cost: #30 = @SUM(#1..#10) * #20 Discount: #20: IF @SUM(#1..#10 > 100 THEN #20 = .9 ELSE #20 = 1 Q & A Application Note Rev. 6/92 #2111 Page 2 of 2