* contrib/gtwvg/tests/demowvg.prg
* contrib/gtwvg/tests/wvgwvtclasses.prg
* contrib/hbct/doc/en/dattime3.txt
* contrib/hbct/tests/datetime.prg
* contrib/hbide/ideconsole.prg
* contrib/hbnf/any2any.prg
* contrib/xhb/decode.prg
* doc/en/datetime.txt
* doc/hdr_tpl.txt
* examples/gtwvw/tests/cbtest1.prg
* examples/gtwvw/tests/cbtest6.prg
* examples/gtwvw/tests/drawimg.prg
* examples/gtwvw/tests/ebtest7.prg
* examples/gtwvw/tests/inpfocus.prg
* examples/gtwvw/tests/maximize.prg
* examples/gtwvw/tests/wvwmouse.prg
* examples/gtwvw/tests/wvwtest9.prg
* examples/hbapollo/tests/test02.prg
* examples/hbapollo/tests/test09.prg
* examples/hbapollo/tests/test11.prg
* examples/hbapollo/tests/test12.prg
* examples/hbapollo/tests/test13.prg
* examples/hbapollo/tests/test14.prg
* examples/hbapollo/tests/test15.prg
* examples/hbapollo/tests/test20.prg
* examples/hbapollo/tests/test21.prg
* examples/hbapollo/tests/test22.prg
* examples/hbapollo/tests/test23.prg
* examples/hbapollo/tests/test24.prg
* examples/hbapollo/tests/test25.prg
* examples/hbapollo/tests/test26.prg
* examples/hbapollo/tests/test27.prg
* examples/hbapollo/tests/test28.prg
* examples/hbapollo/tests/test29.prg
* examples/hbapollo/tests/test30.prg
* examples/hbapollo/tests/test34.prg
* examples/hbapollo/tests/test35.prg
* examples/hbapollo/tests/test36.prg
* examples/hbapollo/tests/test37.prg
* examples/hbapollo/tests/test38.prg
* examples/hbapollo/tests/test39.prg
* examples/hbapollo/tests/test41.prg
* examples/hbapollo/tests/test42.prg
* examples/hbapollo/tests/test43.prg
* examples/hbapollo/tests/test45.prg
* examples/hbapollo/tests/test46.prg
* examples/hbapollo/tests/test47.prg
* examples/hbapollo/tests/test50.prg
* examples/hbapollo/tests/test51.prg
* examples/hbapollo/tests/test52.prg
* examples/hbapollo/tests/test53.prg
* examples/hbapollo/tests/test54.prg
* examples/hbapollo/tests/test55.prg
* examples/hbapollo/tests/test56.prg
* examples/hbapollo/tests/test57.prg
* examples/hbapollo/tests/test58.prg
* examples/hbapollo/tests/test60.prg
* examples/hbapollo/tests/test61.prg
* examples/hbapollo/tests/test62.prg
* examples/hbapollo/tests/test63.prg
* examples/hbapollo/tests/test64.prg
* examples/hbapollo/tests/test73.prg
* examples/hbapollo/tests/test74.prg
* examples/hbapollo/tests/test75.prg
* examples/hbapollo/tests/test76.prg
* examples/hbapollo/tests/test78.prg
* examples/hbapollo/tests/test82.prg
* tests/dates.prg
* tests/usrrdd/exarr.prg
! avoid using CTOD() to create dates
! avoid setting SET DATE to arbirary formats
* some formatting
132 lines
5.1 KiB
Plaintext
132 lines
5.1 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
/*
|
|
* File......: any2any.prg
|
|
* Author....: David Husnian
|
|
* CIS ID....: ?
|
|
*
|
|
* This is an original work by David Husnian and is placed in the
|
|
* public domain.
|
|
*
|
|
* Modification history:
|
|
* ---------------------
|
|
*
|
|
* Rev 1.2 15 Aug 1991 23:02:46 GLENN
|
|
* Forest Belt proofread/edited/cleaned up doc
|
|
*
|
|
* Rev 1.1 14 Jun 1991 19:50:54 GLENN
|
|
* Minor edit to file header
|
|
*
|
|
* Rev 1.0 01 Apr 1991 01:00:34 GLENN
|
|
* Nanforum Toolkit
|
|
*
|
|
*/
|
|
|
|
#define BLOCKIFY(x) { || x }
|
|
#define IS_CHAR(x) (VALTYPE(x) == "C")
|
|
#define IS_DATE(x) (VALTYPE(x) == "D")
|
|
#define IS_LOGICAL(x) (VALTYPE(x) == "L")
|
|
#define IS_NUMERIC(x) (VALTYPE(x) == "N")
|
|
#define CASE_AT(x,y,z) z[AT(x,y)+1]
|
|
#define TRIM_NUMBER(x) hb_ntos(x)
|
|
#define NULL ""
|
|
#define IS_NOT_CHAR(x) (VALTYPE(x) != "C")
|
|
#define IS_NOT_DATE(x) (VALTYPE(x) != "D")
|
|
#define EARLIEST_DATE STOD("01000101")
|
|
#define BLANK_DATE STOD()
|
|
#define IS_NOT_ARRAY(x) (VALTYPE(x) != "A")
|
|
#define IS_NOT_LOGICAL(x) (VALTYPE(x) != "L")
|
|
#define IS_NOT_NUMERIC(x) (VALTYPE(x) != "N")
|
|
#define IS_NOT_CODE_BLOCK(x) (VALTYPE(x) != "B")
|
|
#define TRUE (.t.)
|
|
#define FALSE (.f.)
|
|
|
|
#Define XTOC(x) CASE_AT(VALTYPE(x), "CNDLM", ;
|
|
{ NULL, ;
|
|
x, ;
|
|
iif(IS_NUMERIC(x),;
|
|
TRIM_NUMBER(x), ;
|
|
NULL), ;
|
|
iif(IS_DATE(x),DTOC(x),NULL),;
|
|
iif(IS_LOGICAL(x),;
|
|
iif(x,".T.",".F."), ;
|
|
NULL), ;
|
|
x })
|
|
|
|
#command DEFAULT <Param1> TO <Def1> [, <ParamN> TO <DefN> ] ;
|
|
=> ;
|
|
<Param1> := iif(<Param1> == NIL,<Def1>,<Param1>) ;
|
|
[; <ParamN> := iif(<ParamN> == NIL,<DefN>,<ParamN>)]
|
|
|
|
FUNCTION FT_XTOY(xValueToConvert, cTypeToConvertTo, lWantYesNo)
|
|
|
|
DEFAULT lWantYesNo TO FALSE
|
|
|
|
DO CASE
|
|
|
|
CASE cTypeToConvertTo == "C" .AND.; // They Want a Character String
|
|
IS_NOT_CHAR(xValueToConvert)
|
|
|
|
xValueToConvert := XTOC(xValueToConvert)
|
|
|
|
CASE cTypeToConvertTo == "D" .AND.; // They Want a Date
|
|
IS_NOT_DATE(xValueToConvert)
|
|
|
|
xValueToConvert := iif(IS_CHAR(xValueToConvert), ;
|
|
; // Convert from a Character
|
|
CTOD(xValueToConvert), ;
|
|
iif(IS_NUMERIC(xValueToConvert), ;
|
|
; // Convert from a Number
|
|
xValueToConvert + EARLIEST_DATE, ;
|
|
iif(IS_LOGICAL(xValueToConvert), ;
|
|
; // Convert from a Logical
|
|
iif(xValueToConvert, DATE(), BLANK_DATE), ;
|
|
; // Unsupported Type
|
|
BLANK_DATE)))
|
|
|
|
CASE cTypeToConvertTo == "N" .AND.; // They Want a Number
|
|
IS_NOT_NUMERIC(xValueToConvert)
|
|
|
|
xValueToConvert := iif(IS_CHAR(xValueToConvert), ;
|
|
; // Convert from a Character
|
|
VAL(xValueToConvert), ;
|
|
iif(IS_DATE(xValueToConvert), ;
|
|
; // Convert from a Date
|
|
xValueToConvert - EARLIEST_DATE, ;
|
|
iif(IS_LOGICAL(xValueToConvert), ;
|
|
; // Convert from a Logical
|
|
iif(xValueToConvert, 1, 0), ;
|
|
; // Unsupported Type
|
|
0)))
|
|
|
|
CASE cTypeToConvertTo == "L" .AND.; // They Want a Logical
|
|
IS_NOT_LOGICAL(xValueToConvert)
|
|
|
|
xValueToConvert := iif(IS_CHAR(xValueToConvert), ;
|
|
; // Convert from a Character
|
|
UPPER(xValueToConvert) == iif(lWantYesNo,"Y",".T."), ;
|
|
iif(IS_DATE(xValueToConvert), ;
|
|
; // Convert from a Date
|
|
! EMPTY(xValueToConvert), ;
|
|
iif(IS_NUMERIC(xValueToConvert), ;
|
|
; // Convert from a Number
|
|
xValueToConvert != 0, ;
|
|
; // Unsupported Type
|
|
FALSE)))
|
|
|
|
CASE cTypeToConvertTo == "A" .AND.; // They Want an Array
|
|
IS_NOT_ARRAY(xValueToConvert)
|
|
|
|
xValueToConvert := { xValueToConvert }
|
|
|
|
CASE cTypeToConvertTo == "B" .AND.; // They Want a Code Block
|
|
IS_NOT_CODE_BLOCK(xValueToConvert)
|
|
|
|
xValueToConvert := BLOCKIFY(xValueToConvert)
|
|
|
|
ENDCASE
|
|
|
|
RETURN xValueToConvert // XToY
|