1. Problem with program

All,

        Below is some code snippets from a project I am currently
working on, the problem is no matter what I put in Rnumber it gives
me the Warning about the range being wrong, this same code seems to
work fine in another include file I have for a different window? Is
there a BETTER way to do range checking on input in win32lib programs,
also when the setFocus(edtRnumber) is executed the cursor disappears,
but edtRnumber has the Focus?

-- Program: GenTools.ew
--
-- Generic Tools
--

global constant FALSE = 0, TRUE = 1

global type boolean(integer b)
    return b = FALSE or b = TRUE
end type

global type YesNo(sequence YN)
    if find('Y', YN) then
        return TRUE
    elsif find('N', YN) then
        return TRUE
    else
        return FALSE
    end if
end type

global sequence junk


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

--------------------------------------------------
global procedure Warn(sequence Msg)
    junk = message_box( Msg, "Invalid Input!",
MB_ICONWARNING+MB_TASKMODAL)
end procedure

-------------------------------------------------

-- end of GenTools.ew --------


-- Program Rotate.ew
--
-- include file for Rotation Window
--

include GenTools.ew

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

    if length(FRnumber) > 2 then
        if not range(FRnumber, "2", "199") then
            Warn( "R Number MUST be between 2 and 199" )
            setFocus(edtRnumber)
        end if
    end if
end procedure

onLostFocus[ edtRnumber ] = routine_id( "onLostFocus_edtRnumber" )

-- end of Rotate.ew ---------

TIA for ANY Help!!!

+ + +  Rev. Ferlin Scarborough  -  Centreville, Alabama  -  USA

new topic     » topic index » view message » categorize

2. Re: Problem with program

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 message » categorize

3. Re: Problem with program

Hawke wrote:
>
> --------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
>
>
> etc etc....
>

THANKS Hawke, the above worked fine.

Later,

+ + +  Rev. Ferlin Scarborough  -  Centreville, Alabama  -  USA

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu