'FEET2INS - conv feet/inches to metres

external  remove() ipath fentrybox() messbox() sch fgp bgp scw Background()
external  cpath popuplist() messboxwait()

public    $itemtype ptstr

global    x lx $meas #feet i z h #inch #metres #conv msg1 F2M() M2F()
global    ReturnToMenu() S1 S2


MAIN
while true
  Background()
  s1="Imperial˙to˙Metric"
  s2="Metric˙to˙Imperial"
  x = popuplist(10,30,13,S1&S2,"",1,0)
  if x = -1
    exit while
  end if
  if ptstr=S1
    #conv = 3.280840
    F2M(14,26,29)
  else
    M2F(14,26,29)
  end if
end while

  ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION F2M(r,c,l)
while true
  x = fentrybox(" Enter feet and inches using ' as separator ",6,"*6{[1234567890']}","")
  if x = -1
    return (1)
  end if
  $meas = ptstr
  lx = len($meas)
  #feet = ""
  #inch = ""
  for i = 1 to lx
    z = mid($meas,i,1)
    if z = "'"
      exit for
    else
      #feet = #feet|z
    end if
  end for
  if len(#feet) <> lx
    for h = i+1 to lx
      z = mid($meas,h,1)
      #inch = #inch|z
    end for
    if val(#feet) > 0
      if val(#inch) > 11
        messbox(" Idiot!! Must be less than 12 inches ",0,0,1)
        continue while
      end if
    end if
    #metres=fixed((val(#feet)+(val(#inch)/12))/#conv,2)
  else
      #metres=fixed(val(#feet)/#conv,2)
    end if
    msg1 = #metres|"m."
'     screen print r+1 c+(l/2)+4 fgp bgp msg1
'     inchar
    messboxwait(msg1,0,0,1)
    screen clear box r+1 1 r+1 scw 0 0 no-border
  end while
END FUNCTION ' F2M()


FUNCTION M2F(r,c,l)
  while true
    x = fentrybox(" Enter feet'inches ",6,"*6{[1234567890']}","")
    if x = -1
      exit while
    end if
    $meas = ptstr
    lx = len($meas)
    #feet = ""
    #inch = ""
    for i = 1 to lx
      z = mid($meas,i,1)
      if z = "'"
        exit for
      else
        #feet = #feet|z
      end if
    end for
    if len(#feet) <> lx
      for h = i+1 to lx
        z = mid($meas,h,1)
        #inch = #inch|z
      end for
      if val(#feet) > 0
        if val(#inch) > 11
          messbox(" Idiot!! Must be less than 12 inches ",0,0,1)
          continue while
        end if
      end if
      #metres=fixed((val(#feet)+(val(#inch)/12))/#conv,2)
    else
      #metres=fixed(val(#feet)/#conv,2)
    end if
    msg1 = "="&#metres|"m."
    screen print r+1 c+(l/2)+4 fgp bgp msg1
    inchar
    screen clear box r+1 1 r+1 scw 0 0 no-border
  end while
END FUNCTION ' M2F()


