Attached here is a much improved TextBox MaskEdit example program.
The program now displays the mask prior to the user starting to enter characters into the TextBox. The characters entered are validated as the user enters them. There are 5 edit masks included in this example program. They are:
mDate mask = __/__/____
mMoney mask = 0.00
mSSN mask = ___-__-____
mPhone mask = (___) ___-____
mProperCase (no visable mask, but UCASEs 1st letter of each word)
The Functions can be used two ways: as a Command or as a Function
Used as a Command the function call should be placed in the TextBoxes EN_CHANGE Function. When used this way the functions checks/validates each character entered and maintains the mask for the TextBox. An example call would be:
mPhone (HWND_FORM1_Text1)
Used as a Function you can call it anywhere in your program and it will return the RawData in the MaskEdit TextBox. This is useful when storing data in a database and you want the mask characters stripped from the data. Example call:
RawData = mPhone (HWND_FORM1_Text1)
Hope this proves useful for you.
Much thanks to Paul Squires for helping me get past a couple of difficult problems.
01/02/2010
Added code to MaskEdit that prevents it from being recursively called before it finishes. A new version has been posted.
Note on use of these functions: Paul brought to my attention that it would be wise to prevent this code from firing until after the form is created. To do this:
* Create a global ie:
gAllowTextChange as LONG
* Set global TRUE at end of FORM_WM_CREATE ie:
gAllowTextChange = %TRUE
* In each TEXT_EN_CHANGE function (as first line) place ie:
If gAllowTextChange = %FALSE Then Exit Function