Page 1 of 1

Editing a numeric field

Posted: Tue Mar 17, 2009 7:12 pm
by warrenk
I have a numeric field which I limited the size to 7 digits:

on keyDown theKey
if theKey is a number and the length of me <7 then
pass keyDown
end if
end keyDown

When I put 7 digits in the field and tab back into the field, I try to enter a new number and it doesn't allow me. My key strokes don't work until I delete the value first.

I have used the command:
select the text of field "Quantity Ordered"
...which selects the whole field. Shouldn't the value get overwritten when the field is selected and I key a new value?

Hopefully I explained myself clearly. :)


Thanks for any help!
Warren

Posted: Tue Mar 17, 2009 7:58 pm
by Janschenkel
Upon keyDown the insertion hasn't happened yet. You could check the selectedChunk to see if anything in the field is selected.

Code: Select all

on keyDown pKey
  local tOkeyFlag, tSelectionStart, tSelectionEnd
  put false into tOkayFlag
  if pKey is a number then
    put word 2 of the selectedChunk into tSelectionStart
    put word 4 of the selectedChunk into tSelectionEnd
    if tSelectionEnd > tSelectionStart or length(the text of me) < 7 then
      put true into tOkayFlag
    end if
  end if
  if tOkayFlag is true then
    pass keyDown
  else
    beep
  end if
end keyDown
HTH,

Jan Schenkel.

Posted: Thu Mar 19, 2009 1:55 pm
by warrenk
Jan,

Thanks again!!!! This solution worked perfectly.

Warren