Re: why I can't input chars in the entryfield ?



Harry wrote:

iwidgets::entryfield .getDate.efCode -labeltext "Stock Code:" -validate
{check_code %W "%c"}

proc check_code {entry char} {
set current [$entry get]
set len [string length $current]

if {$len == 8} {
$entry delete 0 end
$entry insert 0 "$current"
}

if {$len == 8 && [regexp {s[z|h][\d]{6}?} $current]} {
return 1
}
return 0
}

Here my proc check_code is to insure the input is like "sz000063",
Do you guys have any better solutions?


OK,
You're doing a few things wrong here ;)
One is you are never looking at the new character - all your
checking is based on the current widget state (i.e. you aren't
looking at what adding the new char does. you're also doing a bunch of
unneccessary stuff where you delete and readd the exact same contents
now point in that. And finally your check is only looking for something
that matches the final state all 8 chars that match your RE so first of
all you are always dealing with an empty field, ignoring input and for
a final answer so you will always fail. If you looked at the new stuff
coming in it would only work if you pasted it in all at once. So, that
being said I would propose the following:

use the %P substitution char which gives you a lookahead at what will
be in your entry if you allow the edit and make sure your RE will
match partial answers so the user can enter things

iwidgets::entryfield .getDate.efCode -labeltext "Stock Code:" \
-validate {check_code %P}

proc check_code {str} {
return [regexp {s([h|z]\d{0-6})?}} $str]
}

that RE should match a single s, an s followed by z or h, or
one of those char combos followed by zero to six chars.

Bruce
.



Relevant Pages

  • [RFC] [Patch 4/4] timer_stats slimmed down: using statistics infrastucture
    ... (>80 char lines because of symbol names, ... * tstat entry structs only get allocated while collection is ... -static void reset_entries ... -static struct entry *alloc_entry ...
    (Linux-Kernel)
  • Re: what is the meaning of "char **option"?
    ... address of a location that holds the address of a location of a char. ... *option points to the first entry of the choices array, ... long as the entry is not NULL ... i compile it by GCC 4 on ArchLinux ...
    (comp.lang.c)
  • Re: System.Text.RegularExpressions sintaxis
    ... it find any char & or % or | ... /// The main entry point for the application. ... [STAThread] ... static void Main ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem using schema.ini
    ... Each entry looks somewhat like this: ... Col2=Firstname Char Width 50 ... >I created a test filel with data, ... John Nurick [Microsoft Access MVP] ...
    (microsoft.public.access.externaldata)
  • Re: missing hard drive space
    ... proc /proc proc defaults 0 0 ... # Entry for /dev/sda1: ... open up a terminal (i.e. a command-line) and type there: ... This will show how much free space you have ...
    (Ubuntu)