Home > Archive > PowerBuilder > February 2005 > Questions on Edit Masks
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Questions on Edit Masks
|
|
| Hitman_in_Wis 2005-01-26, 8:58 pm |
| I cant seem to find any good sources of information on the use of edit
masks and the wildcards used (such as X for any char).
If someone could point me in the right direction, that would be great.
What I really need to find out is if it possible to set up an edit mask
so that it accepts only certain characters, such as 0-9 and A-F for a
hexidecimal mask?
| |
| bgibney 2005-02-01, 10:25 pm |
| quote: Originally posted by Hitman_in_Wis
I cant seem to find any good sources of information on the use of edit
masks and the wildcards used (such as X for any char).
If someone could point me in the right direction, that would be great.
What I really need to find out is if it possible to set up an edit mask
so that it accepts only certain characters, such as 0-9 and A-F for a
hexidecimal mask?
The wildcard characters that you can use when defining the mask property for either an EditMask control or a column with an EditStyle of EditMask are poorly documented in the help, you're right.
Fortunately, you can click on the right-arrow button at the right-most edge of the edit box where you type in your format to see the allowable characters displayed in a popup.
On an EditMask control (placed say on a Window or a UserObject), you define the Mask property on the "Mask" tab of the Properties pane. Here, you first should specify the data type the EditMask control will be capturing (using the MaskDataType DropDown on this tab); your choice here changes the characters that PowerBuilder will recognize as valid, and consequently which ones it displays when you click the arrow to the right of the "Mask" property edit directly above.
Specify a StringMask! type, and you can enter a string composed of characters such as "!" for only Uppercase character, ^ for Lowercase, # for a numeric digit, "a" for alphanumeric chars, and "x" for any character. Numerics are simpler, with a # being used to represent a "suppress zeros" digit, and 0 (zero char) representing a digit where 0 will show. The behavior of this is pretty much as is discussed in the help files for display formats.
Of course, date and time and other data types have their own characters; you'll just have to experiment some. Also note the masks that are pre-defined types such as [currency] and [time] -- they have special meanings that I think you can find in the help files.
In a DataWindow object, the behavior is pretty much the same, only you don't get to choose the data type for the column (you've already established that in your result set long before you can plop it in a particular band in the design view). The Properties pane for a column contains an Edit tab, and once you choose an EditStyle of EditMask, the Mask property displays, with that same arrow button to the right of it. As I look at it now, there seems to be a much bigger list of options for some data types here than in the EditMask control itself, so play around with them if you want.
As to your question, can you define a mask such that users can only enter a valid hex digit, I'd say "that depends".
You can't store A-F in a numeric data type, so you've got to start with a character / string data type column. That defines the mask characters you can use, and there's no wildcard character for "any valid hex character", so the best you could do would be to allow the user to type in any alphanumeric character (e.g. "aaaaaaaa"); this will at least prevent them from entering tildes and apostrophes and the like.
But, you've still got to do something about when they enter Ms and Qs and Ws, or even making the lowercase letters change to uppercase to make it pretty.
You can wait until the ItemChanged event fires, or you can put code in the EditChanged and (sort of, you'll see what I mean) intercept the user and correct bad values as they type.
Beware that EditMasks have some quirky behavior once you start tapping into the underlying windows events to try to intercept the W a user enters before it even displays... If you insist, there's plenty of documentation out there on which pbm_ events map to which windows events for which control type, and you can always go one further and read up on the Win32 SDK then slap some code in the "other" event that handles only the underlying windows edit notifications that you want...
I'd probably allow alphanumerics and handle it in the EditChanged event, I suppose.
Bill Gibney
PB guy for much too long now... |
|
|
|
|