challange

new topic     » topic index » view thread      » older message » newer message

I've taken a cut (not a very good one) to print a date mask into a editText
field and use onChange() to collect what is typed into the field and wrap
the numbers around the slashes. See if you can do a better job than me. If
you can't maybe you can use the rtn.

It does not validate that what is entered is a date. That woud have to be
done with a onLostFocus() event. This just collects the numbers.

--Date entry and edit
     --  long minimum.
     --  id = create(EditText,"",mainwin,xt,yt,fl,20,ES_NUMBER)
     -- onChange(id) = routine_id("editDate") to call this rtn.
     -- editDate does not validate the date. It just collects the
     --   numbers in a date mask. You check the date with an
     --  onLostFocus() event when the numbers have been entered.
procedure editDate()
integer loc, a, b, lth
sequence text, out, tmp
 tmp = {}
 if working = 0 then
  working = 1
  out = "  /  /  "
  loc = 0
  a = getSelf()
  b = getIndex(a)
  text = getText(a)
  lth = length(text)
  if  lth > 0 then
   for i = 1 to lth do -- strip non numeric (you get the whole thing back)--
    if sch(1,"0123456789",{text[i]}) > 0 then
     tmp = tmp&text[i]
    end if
   end for
   text = tmp
   lth = length(text)
   if lth = 0 then b = 1 end if
   if lth>6 then
    text = text[1..6]
    lth = 6
   end if
   for i = 1 to lth do
     loc +=1
     if find(loc,{3,6}) then
      out[loc] = '/'
      loc += 1
     end if
      out[loc] = text[i]
   end for
   setText(a,out)
   setIndex(a,loc)
  end if
  if find(b,{3,6}) then b += 1 end if
  setIndex(a,b)
  working = 0
 end if
end procedure

> 
...george

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu