TimeValid()

TimeValid()

Determines whether a specified time is valid

Syntax

      TimeValid( <cTime> ) --> lValid

Arguments

<cTime> Designates a character string that contains the time to test.

Returns

TimeValid() RETURNs .T. when <cTime> is a valid time; or .F. when <cTime> is an invalid time.

Description

With input that requires time manipulation, writing your own UDF to check time inputs was unavoidable up to now. TimeValid() permits Complete checking of a time designation. You can use this FUNCTION effectively with a VALID clause within a READ mask.

Note

Note the format for time designations. There must always be two digits for hours, minutes, seconds, and hundredths; otherwise, the time it is regarded as invalid. Valid examples are “12”, “12:59”, “12:59:59”, and “12:59:59:99”. By contrast, invalid examples are “24”, “12:60”, or “12:1”, and/or “12:”. IF you work with time strings that are not completely filled and that you need to check with TimeValid(), then they must be TRIMmed prior to the use of TimeValid() (see following Examples).

Examples

      Using the VALID clause with TRIM, all valid times are
      accepted, even IF no seconds or minutes are specIFied:

      cBegin := SPACE( 11 )
      @ 5, 10 SAY "Please input time for beginning work:";
      GET cBegin VALID TimeValid( RTRIM( cBegin ) )
      READ

      Using a VALID clause without TRIM, hours and minutes must be
      specified, so that TimeValid() can confirm a valid time:

      cBegin := SPACE( 5 )
      @ 5, 10 SAY "Please input time for beginning work:";
      GET cBegin VALID TimeValid( cBegin )
      READ

Compliance

This function is CA-Cl*pper Tools compatible.

Platforms

All

Files

Source is dattime3.c, library is libct.

Seealso

SETTIME()

StrDiff()

StrDiff()

Evaluate the “Edit (Levensthein) Distance” of two strings

Syntax

      StrDiff( <cString1>, <cString2>, [<nReplacementPenalty>], 
               [<nDeletionPenalty>], [<nInsertionPenalty>] ) 
               -> <nDistance>

Arguments

<cString1> string at the “starting point” of the transformation process, default is “”

<cString2> string at the “end point” of the transformation process, default is “”

<nReplacementPenalty> penalty points for a replacement of one character, default is 3

<nDeletionPenalty> penalty points for a deletion of one character, default is 6

<nInsertionPenalty> penalty points for an insertion of one character, default is 1

Returns

<nDistance> penalty point sum of all operations needed to transform <cString1> to <cString2>

Description

The StrDiff() functions calculates the so called “Edit” or “Levensthein” distance of two strings. This distance is a measure for the number of single character replace/insert/delete operations (so called “point mutations”) required to transform <cString1> into <cString2> and its value will be the smallest sum of the penalty points of the required operations.

Be aware that this function is both quite time – O(len(cString1)*len(cString2)) – and memory consuming – O((len(cString1)+1)*(len(cString2)+1)*sizeof(int)) – so keep the strings as short as possible. E.g., on common 32 bit systems (sizeof(int) == 4), calling StrDiff() with two strings of 1024 bytes in length will consume 4 MB of memory. To not impose unneeded restrictions, the function will only check if (len(cString1)+1)*(len(cString2)+1)*sizeof(int) <= UINT_MAX, although allocing UINT_MAX bytes will not work on most systems. If this simple check fails, -1 is returned.

Also, be aware that there can be an overflow when the penalty points are summed up: Assuming that the number of transformation operations is in the order of max(len(cString1), len(cString2)), the penalty point sum, that is internally stored in an “int” variable, is in the order of (max(len(cString1), len(cString2))*max(nReplacementPenalty, nDeletionPenalty, nInsertionPentaly). The StrDiff() does not do an overflow check due to time performance reasons. Future versions of StrDiff() could use a type different to “int” to store the penalty point sum to save memory or to avoid overflows.

The function is aware of the settings done by SETATLIKE(), that means that the wildchar character is considered equal to ALL characters.

Examples

      ? StrDiff( "ABC", "ADC" ) // 3, one character replaced
      ? StrDiff( "ABC", "AEC" ) // 3, dito
      ? StrDiff( "CBA", "ABC" ) // 6, two characters replaced
      ? StrDiff( "ABC", "AXBC" ) // 1, one character inserted
      ? StrDiff( "AXBC", "ABC" ) // 6, one character removed
      ? StrDiff( "AXBC", "ADC" ) // 9, one character removed and one replaced

Tests

      StrDiff( "ABC", "ADC" ) == 3
      StrDiff( "ABC", "AEC" ) == 3
      StrDiff( "CBA", "ABC" ) == 6
      StrDiff( "ABC", "AXBC" ) == 1
      StrDiff( "AXBC", "ABC" ) == 6
      StrDiff( "AXBC", "ADC" ) == 9

Compliance

StrDiff() is compatible with CT3’s StrDiff().

Platforms

All

Files

Source is strdiff.c, library is libct.

Seealso

SETATLIKE()

SetTime()

SetTime()

Sets the system clock

Syntax

      SetTime( <cTime>, [<lMode>] ) --> lSet

Arguments

<cTime> Designates a character string that contains the time that is to become the system time.

<lMode> Designates whether the time should also be set in the CMOS-RAM of an AT. The default is do not write to CMOS-RAM. Note that in Windows platform this adjust is automatic, therefore this parameter is without efect.

Returns

The FUNCTION RETURNs .T. when the time is set successfully.

Description

When you use this FUNCTION to convert the time into the system time from within your xHarbour application, all files acquire this time with each write procedure.

Examples

      Set the system time in each case; but the hardware clock only
      on an AT:

      cNewTime := "10:20:00"
      IF ISAT()
         SetTime( cNewTime, .T. )
      ELSE
         SetTime( cNewTime )
      ENDIF

      Or, more compactly:

      SetTime( cNewTime, ISAT() )

Compliance

This function is CA-Cl*pper Tools compatible.

Platforms

Windows, Linux

Files

Source is dattime3.c, library is libct.

Seealso

SETDATE(), TIMEVALID()

SetPrec()

SetPrec()

Set precision of math functions

Syntax

      SETPREC( <nPrecision> ) -> cEmptyString

Arguments

<nPrecision> digit count between 1 and 16, defaults to 16

Returns

cEmptyString this function always returns an empty string

Description

Be aware that calls to this functions do _NOT_ affect the calculation precision of the math functions at the moment.

Compliance

SETPREC() is compatible with CT3’s SETPREC.

Platforms

All

Files

Source is ctmath.c, library is ct3.

SetDate()

SetDate()

Sets the system date

Syntax

      SetDate( <dDate>, [<lMode>] ) --> lSet

Arguments

<dDate> Designates which date to use to set the system date.

<lMode> Designates whether the date should also be set in the CMOS- RAM of an AT. The default is do not write (.F.). Note that in Windows plataform this adjust is automatic, therefore this parameter is without efect.

Returns

SetDate() RETURNs .T. when the date is successfully set.

Description

When you use this FUNCTION to set the system date from within your xHarbour application, all files acquire this date with each write procedure.

Examples

      Set the system date in each case; but the hardware clock only
      on an AT:

      dNewDate := SToD( "19910730" )
      IF ISAT()
         SetDate( dNewDate, .T. )
      ELSE
         SetDate( dNewDate )
      ENDIF

      Or, more compactly:

      SetDate( dNewDate, ISAT() )

Compliance

This function is CA-Cl*pper Tools compatible.

Platforms

Windows, Linux

Files

Source is dattime3.c, library is libct.

Seealso

SETTIME()

SetAtLike()

SetAtLike()

Determine scan behaviour in some string functions

Syntax

      SetAtLike ([<nMode>] [, <[@]cWildcard>]) --> nOldMode

Arguments

[<nMode>] :

       CT_SetAtLike_EXACT -> characters are compared exactly

       CT_SetAtLike_WILDCARD -> characters are compared using a wildcard character

       The default value is CT_SetAtLike_EXACT.

[<[@]cWildcard>] determines the character that is subsequently used as a wildcard character for substring scanning. The default value is “?”.

NEW: If this parameter is passed by reference [@], the current wildcard character is stored in <cWildcard>.

Returns

nOldMode old (if nMode is a numeric value) or current state of the switch

Description

In the following CT3 functions, strings are compared on a character base:

ATADJUST(), ATNUM(), AFTERATNUM(), BEFOREATNUM(), ATREPL(), NUMAT(), STRDIFF()

With the SetAtLike function, one can determine when characters are considered to match within these functions. If CT_SetAtLike_WILDCARD is set (e.g. “?”), then “?” matches every other character.

<nMode> can be one of the following values that are defined in ct.ch

 
      Definition            | Value 
      ----------------------|------ 
      CT_SetAtLike_EXACT    |   0 
      CT_SetAtLike_WILDCARD |   1

Compliance

This function is fully CT3 compatible, but allows to pass the second parameter by reference so that the current wildcard character can be determined.

Platforms

All

Files

Source is ctstr.c, header is ct.ch, library is ct3.

SayScreen()

SayScreen()

Output to the screen without changing the attribute

Syntax

      SayScreen( <cString>, [<nRow>], [<nCol>] ) -> <cEmptyString>

Arguments

<cString> – the string to output. Although undocumented, can be NIL. <nRow> – row number, defaults to cursor row. <nCol> – column number, defaults to cursor column.

Returns

Returns an empty string.

Description

Outputs a string at specified coordinates without changing character attributes.

Platforms

All

Files

Source is screen1.c, library is libct.

Seealso

SCREENMIX()

SaveToken()

SaveToken()

Save the global token environment

Syntax

      SaveToken() -> cStaticTokenEnvironment

Returns

<cStaticTokenEnvironment> a binary string encoding the global token environment

Description

The SaveToken() function can be used to store the global token environment for future use or when two or more incremental tokenizers must the nested. Note however that the latter can now be solved with locally stored token environments.

Compliance

SaveToken() is compatible with CT3’s SaveToken(),

Platforms

All

Files

Source is token2.c, library is libct.

Seealso

TOKENINIT(), TOKENEXIT(), TOKENNEXT(), TOKENNUM(), TOKENAT(), RESTTOKEN(), TOKENEND()

RestToken()

RestToken()

Restore global token environment

Syntax

      RestToken( <cStaticTokenEnvironment> ) -> cOldStaticEnvironment

Arguments

<cStaticTokenEnvironment> a binary string encoding a token environment

Returns

<cOldStaticEnvironment> a string encoding the old global token environment

Description

The RESTTOKEN() function restores the global token environment to the one encoded in <cStaticTokenEnvironment>. This can either be the return value of SAVETOKEN() or the value stored in the 4th parameter in a TOKENINIT() call.

Compliance

RestToken() is compatible with CT3’s RestToken(),

Platforms

All

Files

Source is token2.c, library is libct.

Seealso

TOKENINIT(), TOKENEXIT(), TOKENNEXT(), TOKENNUM(), TOKENAT(), SAVETOKEN(), TOKENEND()

RATE()

RATE()

Estimate rate of interest for a loan

Syntax

      RATE( nLoan, nPayment, nPeriods ) --> nRate

Arguments

<nLoan> amount of money you get from the bank <nPayment> amount of money you pay back per period <nPeriods> number of periods you pay the loan back

Returns

<nInterest> estimated rate of interest per period, 1 == 100%

Description

RATE() calculates the rate of interest per period for the given loan, payment per periods and number of periods. This is done with the same equation used in the PAYMENT() or PERIODS() function:

<nPayment> = <nLoan>*(<nInterest>/100)/(1-(1+<nInterest>/100)ˆ(-<nPeriods>))

However, this equation can not be solved for <nInterest> in a “closed” manner, i.e. <nInterest> = …, so that the result can only be estimated.

Examples

      // You get a loan of 5172.56, pay 100 back every month for
      // 5 years (60 months). The effective interest rate per
      // period (=month) is

      ? rate( 5172.56, 100, 60 ) // --> 0.005

Tests

      rate( 5172.56, 100, 60.0 ) == 0.005
      rate( 6000.0, 100, 60.0 ) == 0.0

Compliance

RATE() is compatible with CT3’s RATE().

Platforms

All

Files

Source is finan.c, library is libct.

Seealso

PV(), FV(), PAYMENT(), PERIODS()