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!

VALID procedure not working as expected

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
526
Brasil

In a form there are these text boxes:
[pre]
txtROR01 txtRCO01
| | | | ... more text boxes here

txtROR02 txtRCO02
| | | | ... more text boxes here
[/pre]
...

In each TextBox I have:
MyNumber=RIGHT(this.Name,2)

In the VALID procedure for txtROR01 , txtROR02 , I have:

[pre]
frase="thisform.Pageframe1.Page1.txtROR" + MyNumber + ".Value"
IF &frase<>"E" AND &frase<>"R" AND &frase<>" "
Messagebox("Type E or R",0, "Erro")
RETURN .F.
ELSE
RETURN .T.
ENDIF
[/pre]

When executed, if I type for example, A (invalid), instead of E or R (valid choices), the A is displayed in the txtROR01 TextBox and the cursor returns to txtRCO01 (instead of remainig in the txtROR01 TextBox!

I searched in this forum answers for this problem and I found for the error routine RETURN 0 or RETURN -1, instead of RETURN .F., and also Tab Order reassignment for the text boxes, but none of these solved my problem.

Why RETURN .F. is not returning to the same TextBox which has generated error (invalid character was typed)?

Thank you,
SitesMasstec
 
Have you done the following to Debug your code

Code:
frase="thisform.Pageframe1.Page1.txtROR" + MyNumber + ".Value"
[b]SET STEP ON[/b]  && Line Added to Force code Break here to examine &frase
IF &frase<>"E" AND &frase<>"R" AND &frase<>" "

Once you know what &frase is being set to, then you should be able to debug your code.

Good Luck,
JRB-Bldr

 
If you set MyNumber = THIS.NAME, you don't just have the number, you have the full name!

Why do you still work this way? If you already take THIS, then take THIS.VALUE, this will be that texxtboxes value. There is no reason to address the control itself via its name.
THIS is the pronoun similar to the english "I".

THIS.VALUE is the value of thisform.Pageframe1.Page1.txtROR01.Value within the code of thisform.Pageframe1.Page1.txtROR01.
If you want to check THIS.VALUE, then just check THIS.VALUE, don't make it so complicated!

Bye, Olaf.
 
In the VALID procedure for txtROR01 , txtROR02 , I have:

frase="thisform.Pageframe1.Page1.txtROR" + MyNumber + ".Value"

This makes no sense at all to me. Any textbox can refer to itself as This.

If the valid of txtROR01 wants to test its own .Value you'd do it this way:

Code:
If Not Inlist(This.Value, "E", "R", " ")
   Messagebox("error")
   Return .f.
Else
   Return .t.
Endif
 
Hi colleagues!

Olaf and Dan, I cannot use This.Value because the Valid procedure is not in the TextBox. In each of 20 textboxes I have

MyNumber=RIGHT(this.Name,2)
THISFORM.ror_Valid --> call the sub-routine in the Form.


This is in a sub-routine in the Form:
[pre]frase="thisform.Pageframe1.Page1.txtROR" + MyNumber + ".Value"
IF &frase<>"E" AND &frase<>"R" AND &frase<>" "
Messagebox("Type E or R",0, "Erro")
RETURN .F.
ELSE
RETURN .T.
ENDIF
[/pre]
 
Use classes, please.

At least then give this form method a parameter
LPARAMETERS toControl

And then call Thisform.ror_Valid(THIS)
And then toControl.Value is the value.

Or you pass the value, you call Thisform.ror_Valid(THIS.VALUE)
And then the code checks the passed in value.

You have so many possibilities, what are you waiting for?

Bye, Olaf.
 
SitesMasstec said:
In each of 20 textboxes I have
MyNumber = RIGHT(this.Name,2)
THISFORM.ror_Valid --> call the sub-routine in the Form.

So have you put the SET STEP ON command in your Form sub-routine to see what is going on?

How is MyNumber getting passed to the Form's sub-routine from the individual Textbox Valid (or whatever) method?
Is it declared Public, or what?

Also, you are returning a T/F from the sub-routine, but how are you using that Return value within the 20 various VALID (or whatever) methods?

Good Luck,
JRB-Bldr
 
>Also, you are returning a T/F from the sub-routine, but how are you using that Return value within the 20 various VALID (or whatever) methods?

Indeed, you would need to RETURN within all the 20 textboxes.
You still reject to get help, you reject to put your code in one single textbox class, in its Valid event, where it belongs. You don't call a subroutine, you inherit code.

Bye, Olaf.
 

Dear Olaf:

I have not reject any help!! Indeed your help is very, very welcome!

I am slow in trying to learn what some people like you, are expert in VFP.

Please believe me, I am trying to learn all that's seems easy for you.

I'm just afraid to use class here. Sub-routine is clearer for me, in my degree of VFP knowlegde.

My Form works fine, except for just this Valid procedure, that puts the cursor in the next text box instead of putting the cursor in the same textbox thar generated de error.

I'm working with your advice just now.

Thank You.
Tony
SitesMasstec
 
Here is a link to my Form:

Duvida2_ishfb2.jpg


Thank you.
SitesMasstec
 
You don't call the Init, do you?

LPARAMETERS has to go into the routine you call with a parameter.

Bye, Olaf.

Edit: In case you pass on THIS.VALUE you pass on the value and not the control. The receiving parameter should be named describing what it is. if you pass THIS the name toControl described that the parameter is the control as an object reference. If you pass THIS.VALUE you recevie a value so the parameter then should be named tcValue. Prefix t is always a norm for parameeters. p is not used as the p prefix is for private variables, not parameters. You can remember t is for parameters, if you remember it as t for taken in values. The second letter is for the type and o is for object, c is for character and other letters than o and c are as TYPE() or VARTYPE() would give them, there is v for variant, where you can receive any type and that's possible in VFP, too. So tvValue would be a good name, if you'd not know whetere to receive a character value or date, datetime, number, etc.

These naming conventions are no guarantee, but point out the intention also to future developers. It's good to know the naming conventions, though even VFP itself is not strictly obaying them, eg leaving off the t prefix.
 
I am not discounting Olaf's suggestion of using a Class.

But if you are going to stick with using things as they are......
OK, I see where you try to send THIS.Value to ror_valid.
But you do not have an LPARAMETERS line in ror_valid to receive it (Olaf mentioned this above).

And I still do not see how MyNumber is supposed to get to ror_valid.

For the last time, why don't you put a SET STEP ON into your ror_valid just before your IF line.
Then when the code Suspends and automatically opens the VFP TRACE window you can examine the values for &frase and MyNumber as is 'seen' by ror_valid, and you can examine anything else - such as single step through its code to see what is going on.

It might not hurt for you to go to: and look over the video named: Building a Simple Application - Pt. 2.
It mentions: One highlight of this video is the use of the Visual FoxPro Debugger.

Also, as I said earlier, ror_valid is Returning T/F, but you are still not using that Return value in the actual Textbox Valid method.
So despite displaying the different Messageboxes within ror_valid itself you might as well be Returning TRUE all the time since you never use its value after returning to the routine which called it.

Good Luck,
JRB-Bldr
 

Fact:
The cursor was stopping at the next TextBox (which is a Read Only till the previous TextBox content is Valid, an 'E' or 'R' was typed)

The problem was solved in the following way:
If that 'next TextBox" is Read Only, the cursor ir forced to the previous TextBox:

The next TextBox / GotFocus has now these added lines, in its beggining:
[pre]
frase="thisform.Pageframe1.Page1.txtRCO" + MyNumber + ".ReadOnly"
IF &frase=.T.
frase="thisform.Pageframe1.Page1.txtROR" + MyNumber + ".BackColor"
&frase=RGB(255,255,255)

frase="thisform.Pageframe1.Page1.txtROR" + MyNumber + ".SetFocus"
&frase
ENDIF
[/pre]
Of course this is not an elegant way; I will try to use your advices in the Form as soon as I learn them.

Thank you very much,
Tony
SitesMasstec




 
not elegant" is very lightly describing it. Programming obvioulsy is not your strength.

Without addressing to use classes instead, you're checking whether some control is readonly, then set backcolor white and set focus to it.
Are you aware readonly does not influce backcolor as Enabled does? Are you aware of DisabledBackcolor?

Readonly just means you can't type in a control, but you can set focus to it and you can select text and copy it. Enabled=.F. is disabling a control, setting backcolor greyish and you can't put the cursor into it, also not with Setfocus.

The behaviour you want could be solved by rather using Enabled=.F.

Also, if the first of two textboxes only has two valid values, why not use a checkbox instead? Checked could mean E(nabeld), unchecked R(eadonly(disabled).

Overall the whole threads of about one or two weeks you're just concerned with the concept of a combined control that let's a user set a textbox enabled or disabled, readonly or writable, it's still a bit uncertain what you want, but as a much simpler way you could do this with the main texbox only and program it's RightClick event to toggle it's state.

For example put a new textbox on the form and in the RightClick do:
Code:
If THIS.Enabled
   This.Enabled=.F.
ELSE
   This.Enabled=.T.
ENDIF

Now you can toggle the control to be able to receive focus or not.

Bye, Olaf.
 
Hi Olaf!

I'm turning back the textbox backcolor to white because it was already Enabled and in red backcolor previously (when error was detected I had turned it red color, when invalid key was typed inside it).

Just to clarify:
Code:
 E(nabeld), unchecked R(eadonly(disabled).
I mean: E="Estoque" (Inventory), R="Receita" (Recipe), not Enabled/ReadOnly, sorry for the confusion of characters

Yes, I know that greyish textbox means it is ReadOnly.

Thank you,
SitesMasstec




 
You still don't see that this would cover your needs, too, even if you want to set something else and toggle between two states manually.

And besides: Readonly does not change backcolor of a control, there only is a DisabledBackColor, that becomes the backcolor for Enabled=.F. and not for ReadOnly=.T.

There is no readonly backcolor.

Bye, Olaf.
 
So why are you using a textbox here, when you only want one of two particular values? Why not just use option buttons?

Tamar
 

Hello Tamar!

Yes, I thought about using Combo box or Option button, as you can see in the figure, but I have not enough space in the Form for presenting any of these in a reasonable way.

I am not able to upload the figure to show here, but please see the figure above (06 Jun 18:08): look in the first column.

Thank you,
SitesMasstec
 
Do you know that you can make option buttons horizontal?

( ) E ( ) R

If your users know what the two letters mean, you could make such an option group pretty small.

Tamar
 
I have not enough space in the Form

In addition to what Tamar has suggested, the Combobox takes up almost the same amount of space as the TextBox - you can control its size.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top