The Rules for Working with Your Users

□ When converting a number or date to a text string for displaying to your users, or setting it as the .Caption or .Text property of a control, explicitly convert numbers and dates to text according to the WRS, using Format(myNum), or CStr(MyNum).

□ When converting dates to strings, Excel does not rearrange the date part order, so Format(MyDate, "dd/mm/yyyy") will always give a DMY date order (but will show the correct date separator). Use Application.International(xlDateOrder) to determine the correct date order—as used in the sFormatDate function shown at the end of this chapter — or use one of the standard date formats (for example, ShortDate).

□ If possible, use locale-independent date formats, such as Format(MyDate, "mmmdd, yyyy"). Excel will display month names according to the user's WRS language.

□ When evaluating date or number strings that have been entered by the user, use CDate or CDbl to convert the string to a date or number. These will use the WRS to interpret the string. Note that CDbl does not handle the percent sign (%) character if the user has put one at the end of the number.

□ Always validate numbers and dates entered by the user before trying to convert them. See the bWinToNum and bWinToDate functions at the end of this chapter for examples.

□ When displaying information about Excel objects, use the xxxLocal properties (where they exist) to display it in your user's language and formats.

□ Use the xxxLocal properties when setting the properties of Excel objects with text provided by the user (which you must assume is in their native language and format).

0 0

Post a comment