1. challange
- Posted by George Walters <gwalters at sc.rr.com> Aug 24, 2001
- 455 views
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
2. Re: challange
- Posted by Irv Mullins <irvm at ellijay.com> Aug 24, 2001
- 454 views
On Friday 24 August 2001 10:33, George Walters wrote: > > 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. Here's one that might work. It ignores anything but 0..9, and adds the / 's at the appropriate places. It could be extended to accept short numbers separated by slashes, i.e. 1/2/01. -- code generated by Win32Lib IDE v0.10.5 include Win32lib.ew without warning procedure EditText2_onChange () object text integer lastchar,x onChange[EditText2] = nil -- don't respond to change events. text = getText(EditText2) if length(text) > 0 then lastchar = text[length(text)] x = find(lastchar,"0123456789") if x > 0 then if length(text) = 2 or length(text) = 5 then text &= "/" end if else text = text[1..length(text)-1] end if end if setText(EditText2,text) setIndex(EditText2,-1) -- done with changes, reenable event trap: onChange[EditText2] = routine_id("EditText2_onChange") end procedure onChange[EditText2] = routine_id("EditText2_onChange") WinMain( Window1, Normal )
3. Re: challange
- Posted by George Walters <gwalters at sc.rr.com> Aug 24, 2001
- 478 views
Thanks Irv, I thought I would learn something from this. I didn't know about the onChange[] = nil.... I'll try your rtn over the weekend. I'm off to the boat with my laptop to get away from the support phone in about an hour.... ...george ----- Original Message ----- From: "Irv Mullins" <irvm at ellijay.com> To: "EUforum" <EUforum at topica.com> Subject: Re: challange > > On Friday 24 August 2001 10:33, George Walters wrote: > > > > 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. > > Here's one that might work. It ignores anything but 0..9, and adds the / 's > at the appropriate places. It could be extended to accept short numbers > separated by slashes, i.e. > 1/2/01. > > -- code generated by Win32Lib IDE v0.10.5 > > include Win32lib.ew > without warning > > > procedure EditText2_onChange () > object text > integer lastchar,x > onChange[EditText2] = nil -- don't respond to change events. > text = getText(EditText2) > if length(text) > 0 then > lastchar = text[length(text)] > x = find(lastchar,"0123456789") > if x > 0 then > if length(text) = 2 > or length(text) = 5 then > text &= "/" > end if > else text = text[1..length(text)-1] > end if > end if > setText(EditText2,text) > setIndex(EditText2,-1) -- done with changes, reenable event trap: > onChange[EditText2] = routine_id("EditText2_onChange") > end procedure > onChange[EditText2] = routine_id("EditText2_onChange") > > WinMain( Window1, Normal ) > > > > >
4. Re: challange
- Posted by Irv Mullins <irvm at ellijay.com> Aug 24, 2001
- 429 views
On Friday 24 August 2001 14:20, George Walters wrote: > > Thanks Irv, I thought I would learn something from this. I didn't know > about the onChange[] = nil.... I'll try your rtn over the weekend. I'm off > to the boat with my laptop to get away from the support phone in about an > hour.... > > ...george Sheesh! Euphorum does it again - removes some of my code. Below is what "should" have been at the top of the previous code segment: include Win32lib.ew without warning global constant Window1 = create( Window, "Window1", 0, Default, Default, 400, 300, 0 ) global constant EditText2 = create( EditText, "", Window1, 56, 8, 150, 20, 0 ) procedure Nil() end procedure constant nil = routine_id("Nil") -- put onChange procedure here: Regards, Irv