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!

TextBox Validation

Status
Not open for further replies.

ETCMSS

Programmer
May 27, 2012
5
US
Using VFP 6.0, I created a form with a large 3-tab Pageframe on it. I finally got around to writing in the field validation rules using the "Valid" method. I did a quick test using just one Textbox by entering an invalid value. I expected to see the message that I put in the ErrorMessage method (Value too large). Instead, I got STUCK in the Textbox. I couldn't escape out or enter a different value. I couldn't go anywhere! I had to use the Windows Task Manager to get out of the thing.

I had a feeling that the error message was underneath the Pageframe and not visible. I did another test using the Lostfocus method on the same Textbox. I told it to print a bunch of X's in the middle of the screen. I didn't see those either. I then told it to print those X's at the top of the form (above the Pageframe). I saw those!

So the obvious question is this ... how do I get the validation messages to show up on top of the Pageframe? The form itself was already set to Alwaysontop = .F.

Tom
 
I expected to see the message that I put in the ErrorMessage method

First you do not say how you are attempting to display the Error Message.

Are you:
* Using a WAIT WINDOW?
* Or are you using MessageBox()?
* Or have you created your own VFP Form to display the error message?

Next, have you used the command SET STEP ON in your Textbox Validation method as a Debug approach to watch the execution of your Validation code?

With a little more explanation and clarification, we can likely assist you better.

Good Luck,
JRB-Bldr
 
My good old Que book "Using Visual FoxPro 6" stated that if the Valid method for a Textbox returned an .F., it would display the error message that I set up in the Textbox Errormessage method ... assuming that Set Notify is set to On (and it was). [If you have the same book, you'll see the explanation on page 322-323].

The Errormessage was just a simple ... "Value too large" (in a cost Textbox).

I didn't use any code to enter those items ... just the properties window. The same place that I enter the control source, input mask, font bold, etc.

I hope that helps in the clarification.

Tom
 
You probably need to put the validation code into the valid method

Like this
Code:
Valid Method
m.flg = .t.
IF this.value > 10
	m.flg = .f.
ENDIF
return(m.flg)

ErrorMessage Method
WAIT "oh heck, should be <= 10" WINDOW TIMEOUT 20
This will result in two messages - one says 'Invaid Value' the other says 'oh heck...'

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
My good old Que book "Using Visual FoxPro 6" stated that if the Valid method for a Textbox returned an .F., it would display the error message that I set up in the Textbox Errormessage method

That might or might not be true, but it's not the usual way of doing it.

The usual approach is like this:

Code:
* Code in the Valid method
IF THIS.Value > 10 && or whatever the max. value is
  MESSASGEBOX("Value too large")
  RETURN .f.
ELSE
  RETURN .t.
ENDIF

In other words, don't use the ErrorMessage method at all. That's because it is flagged as being "for backward compatibility only".

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I found out what the problem with the errormessage was.

I ALWAYS start off my programs with "Deactivate Windows Screen" to get rid of that big white screen behind my forms. When I commented out that statement I saw a grey bar running across the bottom of that screen when I entered an invalid value into my textbox. There it was .. my error message! The instruction was to Press the Space Bar. That's probably the only thing I didn't try yesterday (I sure banged on the ESC key a lot, though).

OK, so I'll use the MessageBox idea as suggested above by Mike and see how that works out.

Thanks for all of the overnight input!

Tom




 
I'm back.

I did the validation using the "OK" messagebox if the value was too large. It popped up nicely.

However (you knew that was coming), after clicking on the "OK" button, I still had to press the spacebar to get the cursor to go back to the textbox to re-enter a new value.

Is there a setting to make that %$*!&* spacebar thing go away?? I tried a work-around by using the Keyboard command, like so ...

if this.value > 80
messagebox ('Value is too large')​
keyboard ' '​
retval = .F.​
else
[indent ]retval = .T. [/indent]
endif

return retval


It seemed to work once, but on additional textbox entries (same textbox) it locked me up to the point where I, once again, had to use the Windows Task Manager to quit the application, even after pressing the spacebar a few dozen times.


Tom

P.S. How do you get the indent thing to work in these messages? My IF statement preview looks like crap.
 
Tom,

The root of your problem is the DEACTIVATE WINDOW SCREEN command. This is another old construct, which doesn't fit the more modern way of doing things. If you want to hide the outer VFP window, the correct way to do that is to make your forms top-level (the Help will give you more information about that), and then issue either _SCREEN.Visible = .F. (in your main program) or SCREEN = OFF (in a Config.FPW file).

Regarding the use of
, this isn't supported in this forum. Instead, wrap you code in [ignore]
Code:
[/ignore] / [ignore]
[/ignore] tags, and use the spacebar (not the Tab key) to indent.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

The _SCREEN.VISIBLE method worked great! The validation is working nicely. No More "Deactivate Window Screen" for me.

Thanks, Mike.



Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top