Val()

<< Click to Display Table of Contents >>

Navigation:  Available Functions >

Val()

Syntax

Val( <FieldName> )

 

Purpose

To convert character fields to numeric type.

 

Parameters

The name of a character field, or a character expression.

 

Returns

A Numeric Value.

 

Usage

This function is useful when you want to compare the contents of character fields with specific values or expressions of numeric type, or when you wish to perform arithmetic operations on character fields.

 

Example

You want to know all the donors with a code number of one. You're not sure whether your data entry person has been entering the code one's as "1__", "_1_", "__1", or "001". Normally, you would have to check each of the three cases individually, using an .OR. connector like this:

 

(.Code. = "1 ") .OR. (.Code. = " 1 ") .OR.

(.Code. = " 1") .OR. (.Code. = "001")

 

Using the "Val()" function, all you would have to do is convert the contents of the code field to a number, and then compare what the "Val()" function returns to a literal number 1 like this:

 

Val( .Code. ) = 1

 

Notice that we did not surround the 1 in quotes, because it is a specific numeric rather than character value. Note that if there were alpha characters (letters) in the code field, the "Val()" function would only return as its value the first few numeric characters which occur before the first non-numeric character. For example, Val( "1Y2" ) would return a numeric value of one, and not twelve.