COMPILE SUBROUTINE SECONDS_CONV( ConvType, DataIo, SubrLabel, ReturnedValue )
begin condition
pre:
post:
end condition
$insert logical
$insert msg_equates
declare function msg

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

ReturnedValue = DataIo        ; * save off data input by user
status() = valid$             ; * assume successful conversion

BEGIN CASE
	CASE ConvType = 'ICONV'
   		
		if num( DataIo ) then
			ReturnedValue = DataIo
		end else
			* maybe they entered as 00:00
			DataIo = TRIM(DataIo)
			Minutes = field( DataIo, ':', 1 )
			Seconds = field( DataIo, ':', 2 )
			if num( Minutes ) and num( Seconds ) then
				Minutes += 0
				Seconds += 0
				ReturnedValue = (Minutes*60) + Seconds
			end else
				MsgInfo = ''
				MsgInfo<micon$> = '!'
				MsgInfo<mtext$> = 'You must enter a whole number of seconds or MM:SS'
				Void = msg( '', MsgInfo )
				status() = invalid_nomsg$
			end 
		end
	case ConvType = 'OCONV'
		if num( DataIo ) then
			if DataIo > 59 then
				Hours = int( DataIo/60 )
				Minutes = mod( DataIo, 60 )
				ReturnedValue = Hours:':':fmt( Minutes, 'R(0)#2' )
			end else
				ReturnedValue = '00:':fmt( DataIo, 'R(0)#2' )
			end
		end else
			ReturnedValue = DataIo
		end
		swap '00:00' with '' in ReturnedValue
		
	case otherwise$
		ReturnedValue = ''
		status() = invalid_conv$
end case
return

