I was in need of this method like ScrollDate method in TGet Class and I have put little effort on this.
If anybody feels that this is useful, they can make use of it by adding an additional method in TGet Class :
METHOD ScrollTime( nDirection ) under METHOD ScrollDate(nDirection)
Regards,
- Ramesh Babu P
- Code: Select all Expand view
//----------------------------------------------------------------------------//
* Method Added by RAMESH BABU P on 13-06-2010
METHOD ScrollTime( nDirection ) CLASS TGet
LOCAL cFormat, cType
LOCAL cTime
LOCAL nHours, nMinutes, nSeconds, nPos
#ifndef __XPP__
cTime := ::Value
#else
cTime := ::VarGet()
#endif
nPos := ::nPos
cFormat := Set( _SET_TIMEFORMAT, "hh:mm:ss")
nHours := VAL(SUBSTR(cTime,1,2))
nMinutes := VAL(SUBSTR(cTime,4,2))
nSeconds := VAL(SUBSTR(cTime,7,2))
cType := Upper( Substr( cFormat, nPos, 1 ) )
If ! cType $ "HMS" .and. nPos > 1
cType = Upper( Substr( cFormat, nPos - 1, 1 ) )
Endif
do case
case nPos <= 2
nHours += nDirection
If nHours >24 .OR. nHours < 0
nHours := 0
nMinutes := 0
nSeconds := 0
Endif
cTime := StrZero( nHours, 2 ) + ":" + StrZero( nMinutes, 2 ) + ":" + StrZero( nSeconds, 2 )
case nPos >3 .AND. nPos <= 5
nMinutes += nDirection
if nMinutes > 59
nHours += 1
nMinutes := 0
Elseif nMinutes < 0
nMinutes := 59
nHours -= 1
If nHours < 0
nHours := 0
nMinutes := 0
nSeconds := 0
Endif
Endif
cTime := StrZero( nHours, 2 ) + ":" + StrZero( nMinutes, 2 ) + ":" + StrZero( nSeconds, 2 )
If Empty( cTime )
cTime := "00:00:00"
Endif
case nPos >6 .AND. nPos <= 8
nSeconds += nDirection
If nSeconds > 59
nSeconds := 0
nMinutes += 1
If nMinutes >59
nMinutes := 0
nHours += 1
Endif
Elseif nSeconds < 0
nSeconds := 59
nMinutes -= 1
If nMinutes < 0
nHours -= 1
nMinutes := 59
Endif
If nHours < 0
nHours := 0
nMinutes := 0
nSeconds := 0
Endif
Endif
cTime := StrZero( nHours, 2 ) + ":" + StrZero( nMinutes, 2 ) + ":" + StrZero( nSeconds, 2 )
endcase
Set( _SET_TIMEFORMAT, cFormat )
if nDirection > 0
if ::bMax != NIL .and. cTime > Eval( ::bMax )
MessageBeep()
else
::cText( cTime )
endif
else
if ::bMin != NIL .and. cTime < Eval( ::bMin )
MessageBeep()
else
::cText( cTime )
endif
endif
#ifndef __CLIPPER__
do case
case cType == "H"
::SetSel( 0, 2 )
case cType == "M"
::SetSel( 3, 5 )
::nPos := 5
case cType == "S"
::SetSel( 6, 8 )
::nPos := Len(cTime) - 1
end case
#else
::SetPos( nPos )
#endif
RETURN nil