#include "FIVEWIN.CH"
STATIC aDir := {}
static cRegion := 'A', lCommas := .f., lDisplayZeros := nil, cCurSymbol := '$'
static lJsonHuman := .f.
function main
local aDirRaw := Directory( "c:\test\", "DHS" )
local cReadAtStart := {}
local cReadBeforeAction := {}
cReadAtStart := cValToStr( aDirRaw )
? "make some changes to " + "c:\xwinhotel\"
cReadBeforeAction := cValToStr( Directory( "c:\xwinhotel\", "DHS" ) )
if cReadAtStart == cReadBeforeAction
? "no changes"
else
? "directory has changed"
endif
return
//----------------------------------------------------------------//
function cValToStr( uVal, cPic, cInternational, lDispZeros )
local cVal
DEFAULT cInternational := cRegion, lDispZeros := lDisplayZeros
// uVal := xEval( uVal ) // in case uval is codeblock
// cPic := xEval( cPic, uVal ) // in case cpic is codeblock
if ValType( cPic ) == 'B'
cPic := Eval( cPic, uVal )
endif
if uVal == nil
cVal = "" // "nil" 26 aug 2013
elseif ValType( uVal ) == 'A'
cVal := FW_ArrayAsList( uVal, CRLF )
return cVal
elseif ! ( ValType( uVal ) $ "CDLNT" )
return cValToChar( uVal )
elseif Empty( cPic )
if ValType( uVal ) == 'N' .and. cInternational == 'E'
cVal := Transform( uVal, '@E' )
else
cVal := cValToChar( uVal )
endif
/*
if ValType( uVal ) == 'N'
cVal := cNumToStr( uVal, cInternational == 'E' )
else
cVal := cValToChar( uVal )
endif
*/
elseif cPic == '@T'
#ifdef __XHARBOUR__
cVal := If( Year( uVal ) == 0, TTOC( uVal, 2 ), TTOC( uVal ) )
#else
cVal := If( Year( uVal ) == 0, HB_TToC( uVal, '', Set( _SET_TIMEFORMAT ) ), HB_TToC( uVal ) )
#endif
elseif cPic == '@D'
cVal := DTOC( uVal )
elseif ValType( uVal ) $ 'DT' .and. Left( cPic, 1 ) != "@"
if Empty( uVal )
cVal := Space( Len( cPic ) )
else
cVal := Lower( cPic )
cVal := StrTran( cVal, ":mm", ":mi" )
cVal := StrTran( cVal, "dddd", CDOW( uVal ) )
cVal := StrTran( cVal, "ddd", Left( CDOW( uVal ), 3 ) )
cVal := StrTran( cVal, 'dd', StrZero( Day( uVal ), 2 ) )
if 'mmmm' $ cVal
cVal := StrTran( cVal, 'mmmm', If( 'MMMM' $ cPic, Upper( cMonth( uVal ) ), cMonth( uVal ) ) )
elseif 'mmm' $ cVal
cVal := StrTran( cVal, 'mmm', Left( If( 'MMM' $ cPic, Upper( cMonth( uVal ) ), cMonth( uVal ) ), 3 ) )
else
cVal := StrTran( cVal, 'mm', StrZero( Month( uVal ), 2 ) )
endif
if 'yyyy' $ cVal
cVal := StrTran( cVal, 'yyyy', Str( Year( uVal ), 4, 0 ) )
else
cVal := StrTran( cVal, 'yy', StrZero( Year( uVal ) % 100, 2 ) )
endif
if 'hh' $ cVal
cVal := StrTran( cVal, 'hh', StrZero( Hour( uVal ), 2 ) )
endif
if 'mi' $ cVal
cVal := StrTran( cVal, 'mi', StrZero( Minute( uVal ), 2 ) )
endif
if 'ss' $ cVal
#ifdef __XHARBOUR__
cVal := StrTran( cVal, 'ss', StrZero( Secs( uVal ), 2 ) )
#else
cVal := StrTran( cVal, 'ss', StrZero( HB_Sec( uVal ), 2 ) )
#endif
endif
endif
else
cVal := Transform( uVal, cPic )
endif
if Empty( uVal ) .and. lDispZeros != nil .and. ValType( uVal ) $ "DNT" // date, number, datetime
if lDispZeros
if Empty( cVal ) .and. ValType( uVal ) == 'N'
cPic := LTrim( StrTran( StrTran( StrTran( StrTran( cPic, '@Z ', '' ), '@z ', '' ), 'Z', ), 'z', '' ) )
endif
cVal := Transform( uVal, cPic )
else
cVal := Space( Len( cVal ) )
endif
endif
/*
if Left( cVal, 1 ) == "*" .and. Len( cVal ) > 2 .and. ValType( uVal ) == 'N'
cVal := cNum2ExpFormat( uVal, Max( Len( cVal ) - 4, 0 ) )
endif
*/
if "*" $ cVal .and. ValType( uVal ) == 'N' .and. !Empty( cPic ) .and. !( '*' $ cPic )
cVal := StretchPicture( uVal, cPic )
endif
return cVal
//----------------------------------------------------------------------------//
function FW_ArrayAsList( aItems, cDelim )
local cStr := ''
DEFAULT cDelim := ','
if ! Empty( aItems )
cStr := cValToStr( aItems[ 1 ] )
AEval( aItems, { |u| cStr += ( cDelim + cValToStr( u ) ) }, 2 )
endif
return cStr
//----------------------------------------------------------------------------//
static function StretchPicture( nVal, cPic )
local cVal, nn
do while "*" $ ( cVal := Transform( nVal, cPic ) )
if nn == nil
nn := AAT( { '#', '9', '.' }, cPic )
if nn == 0
nn := Len( cPic ) + 1
endif
endif
cPic := Left( cPic, nn - 1 ) + "9" + SubStr( cPic, nn )
enddo
return cVal
//----------------------------------------------------------------------------//