Re: Problem with program

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

Ferlin wrote:
> Is there a BETTER way to do range checking on input in win32lib programs,
> global function range(sequence num, sequence lowest, sequence highest)
>     if compare(num,lowest) >= 0 and compare(num,highest) <= 0 then
>         return TRUE
>     else
>         return FALSE
>     end if
> end function

--------breaking the above up gives you more options and/or
--------tools to use, and easier to read/debug code...

include get.e
global function atom_range(atom test, atom low, atom high)
   return (test >= low) and (test <=high)
end function

global function seq_range(sequence num, integer low, integer high)
--the parameters for this function IMHO *should* be
--sequence, atom, atom, BUT, if you are enforcing type on this
--function, then we shall leave them be :)
   num = value(num)
   if num[1] = GET_SUCCESS then
        return atom_range(num[2],low,high)
   end if
   return FALSE
end function

> procedure onLostFocus_edtRnumber()
>     -- range for rnumber is 2 - 199
>     FRnumber = getText(edtRnumber)
>     if length(FRnumber) = 1 then
>         if not range(FRnumber, "2", "9") then
>             Warn( "R Number MUST be between 2 and 199" )
>             setFocus(edtRnumber)
>         end if
>     end if
---new usage:
if length(FRnumber) = 1 then
   if not seq_range(FRnumber,2,199) then
      Warn( "R Number MUST be between 2 and 199" )
      setFocus(edtRnumber)
   end if
end if

etc etc....

enjoy! --Hawke'

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

Search



Quick Links

User menu

Not signed in.

Misc Menu