compile subroutine rds_thick_valid(ConvType, DataIo, Branch, ReturnedValue)
begin condition
pre:
post:
end condition
declare function msg, get_property, set_property
declare subroutine update_index, extract_si_keys

$insert logical
$insert msg_equates
$insert rds_equ
$insert rds_layer_info_equ

equ valid$         to 0    ;* successful
equ invalid_msg$   to 1    ;* bad data       -   print error message window
equ invalid_conv$  to 2    ;* bad conversion -          "         "
equ invalid_nomsg$ to 3    ;* bad but do not print the error message window
equ CrLf$          to char(13):char(10)

ReturnedValue = DataIo       
status() = Valid$

begin case
   case ConvType = 'ICONV'
       *PartNum = xlate( 'RDS', get_property( @window:'.RDS_NO', 'TEXT' ), rds_part_num$, 'X' )
       ** moto part # may terminate with LL or L so swap LL with '' and then if part[-1,1] = L then
       ** set to ''
       *swap 'LL' with '' in PartNum
       *if PartNum[-1,1] = 'L' then
       *   PartNum[-1,1] = ''
       *end
       *MotoTotThick2ndResPns = xlate( 'CONFIG', 'MOTO_TOTTHICK_2ND_RES_PNS', '', 'X' )
       *locate PartNum in MotoTotThick2ndResPns using @vm setting Fpos then
       *   * Combine the thickness cause motorola wants total thickness
       *   * based on both layers
       *   LayerInfo = get_property( @window:'.LAYER_INFO', 'TEXT' )
       *   ThickMin = LayerInfo<1,RLThickMin$>
       *   ThickMin = oconv( ThickMin+@record<rds_thick_min$>, 'MD2' )
       *   ThickMax = LayerInfo<1,RLThickMax$>
       *   ThickMax = oconv( ThickMax+@record<rds_thick_max$>, 'MD2' )
       *   AddlMsg  = 'For total thickness of both layers'
       *end else
          ThickMin = get_property( @window:'.THICK_MIN', 'TEXT' )
          ThickMax = get_property( @window:'.THICK_MAX', 'TEXT' )
          AddlMsg  = ''
       *end
       DataIo = oconv( DataIo, 'MD2' )
       if ( DataIo >= ThickMin ) and ( DataIo <= ThickMax ) else
          Msg = quote( DataIo ):' does not fall into the thickness specification...':AddlMsg:CrLf$:ThickMin:' - ':ThickMax:'.':Crlf$:'Please verify that this is the correct reading.'
          MsgInfo = ''
          MsgInfo<mtext$> = Msg
          MsgInfo<micon$> = '!'
          Void = msg( '', MsgInfo )
          *status() = invalid_nomsg$
          * let it be valid cause it may really be out of spec
       end
   case ConvType = 'OCONV'
      * no output
      ReturnedValue = DataIo
   case otherwise$
      ReturnedValue = ''
      status() = invalid_conv$
end case
return
