[Gambas-user] Miscellaneous routines for text box validation

Richard richard.j.walker at ...247...
Sat Feb 16 03:26:04 CET 2008


On Friday 15 February 2008 02:52:09 Richard wrote:
> On Wednesday 13 February 2008 20:46:14 Richard wrote:
> > On Friday 08 February 2008 03:39:07 richard terry wrote:
> > > Hi all,
> > >
> > > My gambas learning project is progressing well (a contacts database
> > > manager), and I've got the point I can create new
> > > people/names/address(es), etc, now have to fine tune the gui, so not
> > > wanting to re-invent the wheel, I wondered if anyone had in their
> > > possession, or pointers to it, code which would do stuff like.
> > >
> > > for textboxes:
> > >
> > > Autocapitalise, or autocaps
> > > Date validation routines/formatting routines
> > > Name auto capitalisation eg for McBeth, or O'Neil etc
> > >
> > > Also In VB  in the textbox routines one had (index, keyascii) and one
> > > could manipulate the keyascii value to whatever to either exclude keys
> > > or autocapitalise things etc
> > >
> > > I wondered how this worked in gambas, as though I can detect the
> > > keypress, I couldnt see a way to send back a changed key value to the
> > > textbox.
> > >
> > > Thanks in anticipation.
> > >
> > >
> > > Richard
> > >
> > >
> > > -----------------------------------------------------------------------
> > >-- This SF.net email is sponsored by: Microsoft
> > > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > > _______________________________________________
> > > Gambas-user mailing list
> > > Gambas-user at lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> > Hi Richard,
> > I did some name and address processing for a data capture post-processing
> > program at work last year which involved processing UK postcodes and Mc,
> > Mac and O' surnames. The problem I had to solve for the surnames was to
> > present them in a uniform format as specified by the customer.
> >
> > I had to be able to take whatever style the operator had used and convert
> > it to whatever the customer expected. The method I chose was to convert
> > all name fields to title case and then search for the "Mc", "Mac" and
> > "O'" patterns so I could capitalise the next letter.
> >
> > That was usually all I needed to do for "Mc" and "O'" as these are quite
> > unique patterns at the beginning of names. The case for "Mac" was
> > complicated by the possibility of a word not being a Scottish name;
> > Macey, Mackie and Macclesfield spring to mind. I handled these using a
> > lookup list in an array. The list should contain all words you don't want
> > to convert, like those three and maybe a dozen others.
> >
> > In Gambas there is no title case function for a string. Just parse out
> > the words using your own white space character list to determine the word
> > breaks and then set the first character of each word to upper case. Now
> > you have me interested in it again I think I'll try a Gambas translation.
> >
> > Richard
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>
> Richard,
> I have attached a simple Gambas project which demonstrates the method I
> used for forcing initial capital letters in names.
>
> It uses a a slightly modified version of the TitleCase() function I sent to
> you to enable smart handling of names like O'Donnell, MacDonald, Mackintosh
> and McVeigh. It also makes a fair job of abbreviations (Mrs, Dr, MP) and
> any it misses are quite easy to add to the relevant look up word list.
> Names like Du Plessis and place names like Southend-On-Sea should work too.
>
> You may also want to add any two or three letter words which might be found
> in Oz that I haven't included.
>
> It is fairly well tested, but I may have introduced unexpected "features"
> as the code is completely different from my original VB implementation of
> the same concepts. If you have any problems just shout out and I'll either
> fix it or just commiserate with you :~)
>
> Richard

I have updated the form to provide some examples of the other types of 
formatting/validation you mentioned. It is not exhaustive but it should 
provide some more ideas to add to the techniques Stefano illustrated.

The new ValueBox widget is great for controlling input of dates, times, 
numbers and the like. Reformatting dates for display is also very easy.

I have provided one example of a text field for structured numbers like 
vehicle registration numbers, postcodes, national insurance numbers. It also 
shows how pattern matching can be used to validate, for example, three 
letters and 4 digits separated by a space character.

> > > I wondered how this worked in gambas, as though I can detect the
> > > keypress, I couldnt see a way to send back a changed key value to the
> > > textbox.

There is an example in Gambas HELP (gb.qt.TextBox.Change) which warns about 
changing the text within the Change event handler as that triggers another 
Change event. The recommended workaround doesn't seem to be present in 
Stefano's example - perhaps it is no longer necessary.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TitleTest-1.0.1.tar.gz
Type: application/x-tgz
Size: 13021 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20080216/6095f126/attachment.bin>


More information about the User mailing list