Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadError and custom properties

Status
Not open for further replies.

mpgalvin

Programmer
Feb 5, 2001
119
IE
I've created a date-combo class as per the instructions in Hetzenwerke's 1001 Things You Wanted to Know About VFP (if you don't have the book, it's pretty basic, a text box, a command button, a calendar control. You can type into the text box, or click the command button to bring up the calendar. double clicking on the calendar fills the text box with the chosen date. I've enhanced it some, but the basis is the same)

The thing is that if you type an invalid date into the text box, I want to avoid the trouble-causing "Invalid date" system message. So I put in a "On ReadError..." and called a procedure to put up a small messagebox and then "keyboard Esc" to revert to the previous value.

Works like a charm.

Now, I've gotten too clever by far and decided that some users will start to type in a date, then try to use the command button to bring up the calendar. This also invokes the messagebox, reverts the textbox, etc. I don't want this to happen.

I've put in a custom property of the class (showmsg) which is set to .t. everywhere except in the MouseMove() event of the command control. So when the user hovers over the button as he's about to click it, showmsg is set to false. I then changed the procedure called by On ReadError to receive showmsg as a paremeter and show the message if true, don't if false. Simple.

However, I can't pass the showmsg property to this procedure

I've tried

On ReadError Do DateError With This.Parent.ShowMsg (in the gotfocus event of the textbox control)

but "This" is only allowed with a method. I also tried putting This.Parent.ShowMsg into a variable and passing that. But that variable's state (.T. or .F.) is only set in the gotfocus event, and so wouldn't be consistent with the ShowMsg property of the class.

At this point, I'm considering a public variable throughout the class, rather than ShowMsg property, which would probably work fine, but I'd like to know for future reference, how would you do this sort of a thing.

[Apologies for the length of this post]
 
You could consider the following, iso showing a message, you could force the user to choose a date from the calendar control. if they cancel, just empty the textbox control or fill in a default date.

So when the user fills in an invalid date, show the calendar control, if they cancel, empty the textbox control.

HTH,
Weedz (Wietze Veld)
My private project:CrownBase source code can be downloaded !!
 
Weedz, thought about that, but the idea was nixed at the table. This is mostly for our users who know how to use a keyboard (the minority), and if for some reason, they accidentally type '34' instead of '23', we don't want the calendar popping up, confusing them and forcing them to stop what they're doing, etc.

Why TPTB thought a messagebox wouldn't confuse them the same way is one of the many mysteries of the universe :)
 
As I understand, you are using a textbox control to enter a date. The message, is it a default VFP message ?

If so, you could consider setting SET NOTIFY OFF.

In our framework, when someone enters an invalid date like 34th of december, they are not allowed to leave the textbox control, which is default VFP behaviour.

HTH,
Weedz (Wietze Veld)
My private project:CrownBase source code can be downloaded !!
 
Yep, done that. That's partly the problem. I'm over-riding the default error message (it causes problems in our app because we have 'desktop' and modal forms, and the message appears on the desktop form, making the active modal form do strange things).

I just don't want our messagebox to appear if the user has decided to stop entering a date half way through (making the date invalid) and presses the command button to bring up the calendar. Basically, ignore that he's just entered an invalid date if he's decided to bring up the calendar control.

Sounds easy...?
 
You could try
On ReadError Do DateError With _screen.activeform.ShowMsg

hth,

Stuart Dunkeld
 
Weedz: not quite sure. The On ReadError function is a legacy from a previous version of the control (not as a class, just 3 seperate controls sitting on a form) I'm not even sure what the difference is between On Error and On ReadError. However, its all moot since I'd have the same problem if I tried On Error Do ... With ....

Stuart, close but no cigar. ShowMsg is a property of the class (VCX control) and so doesn't exist on the form. I guess I could drill down if I knew the name of the control, but I don't want to limit myself to having all controls the same name. Also could cause problems if I tried putting >1 control on a form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top