Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Perform a Case-Insensitive String Comparison without Using Translate()
Force a Field Value to a Boolean Using Rules
Quickly Crop to a Shadow
Sum Repeating Time Values
Preview and Open Forms after Upgrading to Internet Explorer 8
5 MOST POPULAR
Pass Query String Parameters to an ASP.NET Xml Control
Access a Method in a Master Page with Code-Behind
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Change the Default Action of the Power Button on the Windows Vista Start Menu
5 MOST FORGOTTEN
Install Windows 7 Beta onto a Virtual Machine
Configure Lab Color Mode Defaults for Braintrove Articles
Permanently Change the Default Styles for New Word Documents
Enable Themes in Windows Server
Use Logical Operators in Place of Conditional Expressions
Microsoft MVP
This article has been viewed 215 times.

Eliminate NaN and Infinity Errors in Calculations

Page 1 of 2
Written by Gregory Scot Collins
Tuesday, 31 March 2009, 11:47 AM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
When using calculated fields or expression boxes that incorporate division, the likelihood of receiving calculation errors is great. Not only can this look bad in the form, it can cause downstream issues for data stored in a database.
You will encounter two kinds of calculation errors. The first is the NaN error which occurs when attempting calculations with non-numerical values, including blanks. The second is the Infinity and -Infinity errors which occur when dividing by zero or a blank.
NOTE: These errors are actually useful in that they identify data problems that need correction. However, if you don't require a correction and don't want the ugly error messages, you can use the following techniques to replace these errors with a zero or a blank.

Create a test form

To start, create a test form using the following steps:
  1. Create a new blank form.
  2. Open the Data Source task pane.
  3. Add a Decimal field named Dividend.
  4. Add a Decimal field named Divisor.
  5. Add a Decimal field named Quotient.
  6. Double-click Quotient.
  7. In the Field Or Group Properties dialog box, click the Insert Formula button to the right of the Value text box.
  8. In the Formula text box type: ../my:Dividend div ../my:Divisor, and then click OK twice.
  9. Right-click the myFields and choose Controls In Layout Table.
Preview the form and you will note that Quotient has the value NaN, which stands for Not A Number. If you were to type 5 as the Dividend, the Quotient value changes to Infinity. Change the Dividend to -5 and the Quotient is now -Infinity. Exit the preview.

Eliminate just the NaN error

Use the following steps to eliminate the NaN error:
  1. In the Data Source task pane, double-click Quotient.
  2. In the Field Or Group Properties dialog box, click the Insert Formula button to the right of the Value text box.
  3. Replace the existing formula with one of the following:
    1. If you want a zero value, type: translate(../my:Dividend div ../my:Divisor, "aN", "0").
    2. If you want a blank value, type: translate(../my:Dividend div ../my:Divisor, "aN", "").
  4. Click OK twice.
Preview the form and you will note that the Quotient no longer has the value NaN, but zero or blank, depending on which formula you used. Exit the preview.
The translate() function replaces the character 'a' with a zero or nothing, and replaces both instances of the character 'N' with nothing, thus converting the error "NaN" into a zero or a blank.
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.