Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

DynamicInputMask

This is the newest addition to the Dynamic… property group for columns. Like the others, it lets you specify an expression that’s evaluated at runtime for each row in the grid. In this case, the result of the expression provides an InputMask for the column.

Usage

colColumn.DynamicInputMask = cInputMaskExpression
cInputMaskExpression = colColumn.DynamicInputMask

This property finally lets us do something we’ve been wanting to do since FoxPro 2.x—use an appropriate input mask (PICTURE clause) for the expected input in different rows. You provide an expression that results in a valid InputMask and VFP does the rest. Most often, you’ll use either IIF() or a custom function to figure out the right mask. One thing that often trips us up: Make sure that when setting the value, you specify DynamicInputMask as a string, with beginning and ending string delimiters. Otherwise, you can spend quite a while chasing down “Expression is invalid” messages at runtime.

Example

* Specify an InputMask for PostalCode based on the Country.
* This is the short version.
This.DynamicInputMask = "IIF(UPPER(Country) = 'USA'," + ;
   "'99999-9999',IIF(UPPER(Country)='CANADA'," + ;
   "'A9A 9A9','XXXXXXXXXX'))"

See Also

DynamicBackColor, DynamicForeColor, Format, InputMask