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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing user to enter data into a text box

Status
Not open for further replies.

JLF999

Programmer
Jul 11, 2016
6
US
I have a form with several TextBoxes which are bound to variables. The first Textbox has an initial value of 0. I want the user to have to enter a number greater than 0 in order to be able to leave this textbox and move to the next.

I have tried entering code in the LostFocus event but it doesn't seem to have any effect. I thot about using the Valid event but it won't let you SetFocus in that event.

I know there is a way t do this, I just can think of it.
 
It is indeed the Valid event that you want. But you don't want to set focus in that case. Simply return [tt].T.[/tt] or [tt].F.[/tt]

If the value of the textbox is valid, put [tt]RETURN .T.[/tt] at the end of your code in the Valid event. That will cause focus to move to the next control. If it is not valid, [tt]RETURN .F.[/tt] Focus will remain in the offending control until the user eventually gets it right.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You could make the Valid event something like this:
Code:
LOCAL m.lRetVal
m.lRetVal = .t.
IF this.Value = 0
	m.lRetval = .f.
	MESSAGEBOX("You need to enter a value greater than zero",48,"Problem")
ENDIF
return(m.lRetVal)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
I would add that I personally dislike using the Valid in this way. It is technically correct, but not a good user interface, in my opinion.

If, for some reason, the user cannot enter the correct value - or if they don't know the correct value to enter - they will be forced to enter some fictitious value, if only to let them get out of the textbox. It would be better to let them cancel the whole form, and to come back to it when they are ready.

I prefer to do all the validation at the point at which the data is saved. That way, if the user still cannot enter the correct value, they can at least cancel out of the form.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
It's obvious you should have put your "never mind, I figured it out myself" message here instead of starting another thread.

Anyway, you can RETURN Thisform.othercontrol from Valid, too, to set focus to another control for any reason and the most proper way to enforce numeric input >0 will be to use a spinner control with its Keyboard/Spinner Low/High Value properties.

Bye, Olaf.
 
They can always hit the Esc key... but you are probably right.

I think the current 'preferred' approach is to try and present the bulk of the problems with a data entry form at 'execute/save' time, rather than 'Save'=>'this is wrong'=>'fix this'=>'Save'=>'That is wrong'=>'fix that'=>'Save'=>'The other is wrong'...


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
It's obvious you should have put your "never mind, I figured it out myself" message here instead of starting another thread.

Yes, I was going to point that out as well, but I see that other thread has been removed.

But it would also be helpful if you could tell us exactly what you figured out for yourself - what solution you adopted. That's partly because it's useful to get feedback on our replies, but especially because it might be of help to other people with the same problem.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I agree about the bulk report of errors, a simple option is to highlight wrong entries. More to the point are controls, which don't allow wrong entry, as long as you don't need cross checks (date1<date2) things like a spinner with upper and lower bounds are a good thing. Just like a combobox only containing items valid to select or anything like that even not allowing wrong entries. What's bad is, if you can't tab away from a control or click somewhere else and also can't fix the value of the current control. But in simple cases, like >0 values, why not. No rule without any exception.

Bye, Olaf.
 
In a subsequent (DUPLICATE) post, this individual indicated that he had resolved his own issue.

It would have been better if he had posted that into this thread instead of into a new thread, but he did not.
Now the sort-of Duplicate has been removed.

JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top