Subject Re: Entryfield Valid won't work
From Norman Snowden <duluth@msn.com>
Date Thu, 10 Jan 2019 12:16:49 -0500
Newsgroups dbase.getting-started


Mervyn, thank you very much for your analysis and informative information.
I do very little new programing and only for myself. I will try to modernize and be more effective henceforth.

Mervyn Bick Wrote:

> On 2019-01-10 6:49 AM, Norman Snowden wrote:
> >   Update: I am sorry to have posted about this problem. It is now fixed. I can't understand why. Searching for any solution by a lucky trial I reversed the sequence placing the "S" first as: If this.value = "S" or this.value = "N"
> >     test = true
> > Sorry about this. Maybe I need to be a nicer person!
>
> Mm, never sell yourself short.  You've got to be nicer than some of the
> old curmudgeons I know.  :-)
>
> Your problem may have been caused by a typo.  In the code snippets you
> posted, the N was uppercase but the S was lowercase.  When you retyped
> them in reverse order (which should not have affected the code at all)
> you probably made the S uppercase as well.
>
> If the rest of your program will accept N, n, S or s you can change the
> Valid test to
>
>    Function ENTRYFIELD86_valid()
>       *ns9
>       Test = false
>       If upper(this.value) = “N” or upper(this.value) = “S”
>         Test = true
>       endif
>       return test
>
> If the rest of the program requires N and S to be upper case you can use
> the entryfield's KEY event handler to force lowercase characters to
> uppercase.
>
>     function ENTRYFIELD86_key(nChar, nPosition,bShift,bControl)
>        if nChar >= 97 and nChar <= 122 // i.e from a to z
>           nChar -= 32  //Subtract 32 to give the uppercase character
>        endif
>        //Only characters a to z are changed.  Numerals returned unchanged
>        return chr(nChar)
>
>
> Where you have so many controls all using identical event handlers you
> can remove a lot of "clutter" from your code by having just one event
> handler which you then assign to each control.  When Henry Ford built
> his first petrol engine it only had one cylinder.  His reason for this
> was "If anything goes wrong I know where to look."  The same applies
> here. :-)
>
>
>    this.ENTRYFIELD87 = new ENTRYFIELD(this)
>       with (this.ENTRYFIELD87)
>         VALID = class::ENTRYFIELD_VALID
>          KEY = class::ENTRYFIELD_KEY
>          datalink = form.area1.rowset.fields[“ns10”]
>          height = 0.1771
>          left = 0.92
>          top = 2.87
>          width = 0.1771
>          function = “!”
>          fontsize = 8.0
>          fontbold = true
>       endwith
>
>
>    Function ENTRYFIELD_valid()
>       Test = false
>       If this.value = “N” or this.value = “S”
>         Test = true
>       endif
>       return test
>
>
>     function ENTRYFIELD_key(nChar, nPosition,bShift,bControl)
>        if nChar >= 97 and nChar <= 122 // i.e from a to z
>           nChar -= 32  //Subtract 32 to give the uppercase character
>        endif
>        //Only characters a to z are changed.  Numerals returned unchanged
>        return chr(nChar)
>
>
> If you change the constructor code for the first entryfield you can then
> mark and copy the two lines where the VALID and KEY event handlers are
> assigned.  Then simply paste them over the VALID entry in the
> constructor code for the remaining entryfields.  Once you've done this
> you can remove all the unneeded event handlers.
>
> The next time you need to build a form with so many entryfields all of
> which require identical event handlers remember that this is the ideal
> situation in which to use a custom control.  It will only take a few
> minutes to create a suitable custom entryfield control and after that
> you simply place as many instances as you need without any further
> programming.
>
> I note that you are using inverted commas i.e “N” rather than quotation
> marks "N" to delimit the characters.  If it works for you it's not wrong
> but I'm surprised that dBASE will accept this.  My computer gets
> thoroughly upset.
>
> Mervyn.
>
>
>
>
>
>
>
>
>
>
>
>