home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / dblib201.zip / OBSOLETE.PRG < prev    next >
Text File  |  1993-04-27  |  26KB  |  634 lines

  1. *-------------------------------------------------------------------------------
  2. *-- Program...: OBSOLETE.PRG
  3. *-- Programmer: Ken Mayer (CIS: 71333,1030)
  4. *-- Date......: 02/23/1993
  5. *-- Notes.....: The following functions are not necessary using dBASE IV, 1.5,
  6. *--             but have been retained in the current version of the library
  7. *--             system in order to have some compatibility with 1.1.
  8. *-------------------------------------------------------------------------------
  9.  
  10. FUNCTION Empty
  11. *-------------------------------------------------------------------------------
  12. *-- Programmer..: Jerry Wightman (WIGHTMAN)
  13. *-- Date........: ?
  14. *-- Notes.......: Used to check whether a memory variable in dBASE contains
  15. *--               anything, based on type of field. (Pulled from BORBBS)
  16. *--               NOTE: In release 1.5, replace all calls to EMPTY() with
  17. *--               the new:  ISBLANK() function. This will be faster.
  18. *-- Written for.: dBASE IV, 1.1
  19. *-- Rev. History: None
  20. *-- Calls.......: None
  21. *-- Called by...: Any
  22. *-- Usage.......: Empty(<cFld>)
  23. *-- Example.....: @5,10 say "Enter date: " get bDate;
  24. *--                         valid required .not. empty(bDate);
  25. *--                         error chr(7)+"** Date cannot be Empty! **"
  26. *-- Returns.....: Logical (.t./.f.)
  27. *-- Parameters..: cFld  =  Field/Memvar/Expression to check for "Emptiness"
  28. *-------------------------------------------------------------------------------
  29.  
  30.     PARAMETERS cFld       && may be memory variable or database field name
  31.     private cTalk, lReturn
  32.  
  33.     cTalk = SET("TALK")
  34.  
  35.     lReturn = .F.      &&  FALSE means:  variable is NOT empty
  36.  
  37.     do case
  38.        case type( "cFld" ) = "C"
  39.           if len( ltrim(rtrim( cFld )) ) = 0
  40.              lReturn = .T.
  41.             endif
  42.  
  43.         case type( "cFld" ) = "N" .or. type( "cFld" ) = "F"
  44.             if cFld = 0
  45.                 lReturn = .T.
  46.             endif
  47.  
  48.         case type( "cFld" ) = "L"
  49.             lReturn = .F.  && Can't check logical fields
  50.  
  51.         case type( "cFld" ) = "D"
  52.             if cFld = {}
  53.                 lReturn = .T.
  54.             endif
  55.  
  56.         case type( "cFld" ) = "M"
  57.             if len( cFld ) = 0
  58.                                 lReturn = .T.
  59.             endif
  60.  
  61.         otherwise   && TYPE = "U"
  62.             lReturn = .T.
  63.  
  64.     endcase
  65.  
  66.     set talk &cTalk
  67.     
  68. RETURN lReturn
  69. *-- EoF: Empty()
  70.  
  71. FUNCTION NumFlds
  72. *-------------------------------------------------------------------------------
  73. *-- Programmer..: Bowen Moursund (CIS: 76566,1405)
  74. *-- Date........: 07/12/1991
  75. *-- Notes.......: Returns the number of fields in a database structure --
  76. *--               only in the currently selected DBF
  77. *--               NOTE: In release 1.5, replace function NUMFLDS() with
  78. *--               FLDCOUNT() -- built in to 1.5, faster ...
  79. *-- Written for.: dBASE IV, 1.1
  80. *-- Rev. History: 07/12/1991 -- Original
  81. *-- Calls.......: None
  82. *-- Called by...: Any
  83. *-- Usage.......: NumFlds()
  84. *-- Example.....: ? NumFlds()
  85. *-- Returns.....: Number of fields
  86. *-- Parameters..: None
  87. *-------------------------------------------------------------------------------
  88.  
  89.     private nFlds,cFldName
  90.     
  91.     *-- If currently selected database is empty (no dbf file)
  92.     if len(trim(dbf())) = 0
  93.         nFlds = 0                     && set to 0
  94.     *-- we have something ...
  95.     else
  96.         nFlds = 0                     && initialize
  97.         do while .t.                  && loop through the record structure
  98.             nFlds= nFlds + 1           && increment counter
  99.             cFldName = field(nFlds)    && get fieldname
  100.             if len(trim(cFldName)) = 0 && if length = 0,
  101.                 nFlds = nFlds - 1       &&   decrement counter
  102.                 exit                    &&   get out of loop, we're done
  103.             endif                      && endif(length...)
  104.         enddo                         && end of loop
  105.     endif
  106.  
  107. RETURN nFlds
  108. *-- EoF: NumFlds()
  109.  
  110. FUNCTION DateSet
  111. *-------------------------------------------------------------------------------
  112. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  113. *-- Date........: 03/01/1992
  114. *-- Notes.......: Returns string giving name of current DATE format
  115. *--               This is not needed in Version 1.5, in which set("DATE")
  116. *--               returns the format.  Unlike that function in 1.5, this
  117. *--               one cannot distinguish between date formats set with
  118. *--               different terms that amount to the same thing:
  119. *--                     DMY = BRITISH = FRENCH
  120. *--                     MDY = AMERICAN
  121. *--                     YMD = JAPAN
  122. *--               If your users will be using one of these formats and
  123. *--               are sensitive about the name, substitute the one they
  124. *--               want for the equivalent in this function.
  125. *-- Rev. History: 03/01/1992 -- Original
  126. *-- Written for.: dBASE IV, versions below 1.5
  127. *-- Rev. History: None
  128. *-- Calls.......: None
  129. *-- Called by...: Any
  130. *-- Usage.......: DateSet()
  131. *-- Example.....: ?DateSet()
  132. *-- Returns.....: Character
  133. *-- Parameters..: None
  134. *-------------------------------------------------------------------------------
  135.  
  136.     private cCent, cTestdate, cDelimiter
  137.     cCent = set( "CENTURY" )
  138.     set century off
  139.     cTestdate = ctod( "01/02/03" )
  140.     cDelimiter = substr( dtoc( cTestdate ), 3, 1 )
  141.     set century &cCent
  142.     do case
  143.       case month( cTestdate ) = 1
  144.         RETURN iif( cDelimiter = "-", "USA", "MDY" )
  145.       case day( cTestdate ) = 1
  146.         RETURN iif( cDelimiter = "/", "DMY", ;
  147.           iif( cDelimiter = ".", "GERMAN", "ITALIAN" ) )
  148.       otherwise
  149.         RETURN iif( cDelimiter = ".", "ANSI", "YMD" )
  150.     endcase
  151.     
  152. *-- EoF: DateSet()
  153.  
  154. FUNCTION Stampval
  155. *-------------------------------------------------------------------------------
  156. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  157. *-- Date........: 04/07/1992
  158. *-- Notes.......: Passed a 16-character string in the form of the rightmost
  159. *--             : 16 characters returned by the DOS DIR command for a file,
  160. *--             : returns a number that will compare properly in date/time
  161. *--             : order with the numbers returned by this function for other
  162. *--             : files.
  163. *-- Written for.: dBASE IV Versions below 1.5
  164. *-- Rev. History: 04/07/1992
  165. *-- Calls       : None
  166. *-- Called by...: Any
  167. *-- Usage.......: Stampval(<cTimestamp>)
  168. *-- Example.....: IF Stampval("02-22-92  10:54a") > Stampval("04-05-92   5:54p")
  169. *-- Returns.....: Numeric corresponding to time stamp of file
  170. *-- Parameters..: cStamp, a DIR timestamp
  171. *-------------------------------------------------------------------------------
  172.    parameters cStamp
  173.    RETURN 1440 * ( 12 * val( left(cStamp,2)) + val(substr(cStamp,4,2)) ;
  174.        + 372*val(substr(cStamp,7,2)) ) + 60 * val(substr(cStamp,11,2)) ;
  175.        + val(substr(Cstamp,14,2)) + iif(right(cStamp,1)="p",720,0)
  176. *--Eof() Stampval
  177.  
  178. PROCEDURE FullWin
  179. *-------------------------------------------------------------------------------
  180. *-- Programmer..: Ken Mayer (CIS: 71333,1030)
  181. *-- Date........: 05/23/91
  182. *-- Notes.......: Overlays menus or another screen with a full window,
  183. *--               so that processing is done in the window, and one can return
  184. *--               directly to the menus, without redrawing screen and such.
  185. *--               This routine may be a problem in dBASE IV, 1.5 ... use
  186. *--               with caution ...
  187. *-- Written for.: dBASE IV, 1.1
  188. *-- Rev. History: 05/23/1991
  189. *-- Calls.......: None
  190. *-- Called by...: Any
  191. *-- Usage.......: do fullwin with <cColor>,<cWinName>,<cScreen>
  192. *-- Example.....: do fullwin with "w+/b","w_Edit","sc_Main"
  193. *--                * perform whatever actions are needed in the window
  194. *--               deactivate window wEdit
  195. *--               release window wEdit
  196. *--               restore screen from sMain
  197. *--               release screen sMain
  198. *-- Returns.....: None
  199. *-- Parameters..: cColor   = Colors for window
  200. *--               cWinName = Name of window
  201. *--               cScreen  = Name of screen
  202. *-------------------------------------------------------------------------------
  203.     
  204.     parameters cColor,cWinName,sScreen
  205.     
  206.     define window &cWinName from 0,0 to 23,79 none color &cColor.
  207.     save screen to &sScreen.
  208.     activate window &cWinName.
  209.     
  210. RETURN  
  211. *-- EoP: FullWin
  212.     
  213. PROCEDURE SetColor
  214. *-------------------------------------------------------------------------------
  215. *-- Programmer..: Phil Steele
  216. *-- Date........: 05/23/91
  217. *-- Notes.......: Used to set the screen colors for a system. It
  218. *--               checks to see if a color monitor is attached (ISCOLOR()),
  219. *--               and sets system variables, that can be used in SET COLOR OF
  220. *--               commands. You must define the memvars as PUBLIC, see Example
  221. *--               below -- otherwise nothing will work.
  222. *-- Written for.: dBASE IV, 1.1
  223. *-- Rev. History: Borrowed from Phil Steele's PCSDEMO (a public domain
  224. *--               program) and commented a bit more, minor modifications by
  225. *--               Ken Mayer 
  226. *-- Calls.......: None
  227. *-- Called by...: Any
  228. *-- Usage.......: do setcolor
  229. *-- Example.....: in a menu or setup program:
  230. *--               PUBLIC cl_blank,cl_func,cl_help,cl_data,cl_error,;
  231. *--                      cl_entry,cl_stand,cl_menu,cl_warn 
  232. *--               DO setcolor
  233. *--                  by declaring the variables PUBLIC before calling SETCOLOR
  234. *--                  they should be globally available throughout, unless you
  235. *--                  use a CLEAR ALL or RELEASE ALL command ...
  236. *-- Returns.....: None
  237. *-- Parameters..: None
  238. *-------------------------------------------------------------------------------
  239.     
  240.     if file("COLOR.MEM")
  241.         restore from Color.mem additive    && if color.mem exists, restore from it
  242.     else                                && otherwise, create it
  243.         lC           = iscolor()             && remember -- foreground/background
  244.         cl_Blank = "n/n,n/n,n"           && black on black on black ...
  245.         cl_Func  = "n/w"                 && function keys (used in CLRSHOW)
  246.             * if iscolor() = true, define color, otherwise black/white
  247.         cl_Help  = iif(lC,"n/g,g/n,n"      , "w+/n,n/w,n")   && help
  248.         cl_Data  = iif(lC,"rg+/gb,gb/rg,n" , "n/w,w+/n,n")   && data entry fields
  249.         cl_Error = iif(lC,"rg+/r,w/n,n"    , "w+/n,n/w,n")   && error messages
  250.         cl_Entry = iif(lC,"n/w,w/n,n"      , "n/w,w/n,n")    && data entry??
  251.         cl_Stand = iif(lC,"w+/b,b/w,n"     , "w+/n,n/w,n")   && standard screen
  252.         cl_Menu  = iif(lC,"rg+/b,b/w,n"    , "w+/n,n/w,n")   && menus
  253.         cl_Warn  = iif(lC,"rg+/r,w/n,n"    , "w/n,n/w,n")    && warning messages
  254.         save to color all like cl_*        && create COLOR.MEM
  255.     endif
  256.     
  257.     *-- change current color settings to these ...
  258.     set color to &cl_stand                         
  259.     cTemp = extrclr("&cl_data")  
  260.     set color of fields   to &cTemp
  261.     set color of messages to &cTemp
  262.     set color of box      to &cTemp
  263.     cTemp = extrclr("&cl_stand")
  264.     set color of highlight to &cTemp
  265.     
  266. RETURN
  267. *-- EoP: SetColor
  268.  
  269. PROCEDURE SetColor2
  270. *-------------------------------------------------------------------------------
  271. *-- Programmer..: Phil Steele
  272. *-- Date........: 05/23/91
  273. *-- Notes.......: Used to set the screen colors for a system. It
  274. *--               checks a parameter passed by the programmer to see if the
  275. *--               monitor is a color system. It then creates the proper color
  276. *--               combinations based on this ... 
  277. *-- Written for.: dBASE IV, 1.1
  278. *-- Rev. History: Borrowed from Phil Steele's PCSDEMO (a public domain
  279. *--               program) and commented a bit more, minor modifications by
  280. *--               Ken Mayer 11/21/91 -- Modified for parameter ...
  281. *-- Calls.......: None
  282. *-- Called by...: Any
  283. *-- Usage.......: do setcolor2 with "<cYN>"
  284. *-- Example.....: in a menu or setup program:
  285. *--               PUBLIC cl_blank,cl_func,cl_help,cl_data,cl_error,;
  286. *--                      cl_entry,cl_stand,cl_menu,cl_warn 
  287. *--               DO setcolor2 with "Y"
  288. *--                  by declaring the variables PUBLIC before calling SETCOLOR
  289. *--                  they should be globally available throughout, unless you
  290. *--                  use a CLEAR ALL or RELEASE ALL command ...
  291. *-- Returns.....: None
  292. *-- Parameters..: cYN  =  "Y" for color, "N" for mono ...
  293. *-------------------------------------------------------------------------------
  294.     
  295.     parameter cYN
  296.     private lC, cTemp
  297.     
  298.     lC           = iif(cYN="Y",.t.,.f.)  && remember -- foreground/background
  299.     cl_Blank = "n/n,n/n,n"           && black on black on black ...
  300.     cl_Func  = "n/w"                 && function keys
  301.     cl_Help  = iif(lC,"n/g,g/n,n"      , "w+/n,n/w,n")   && help
  302.     cl_Data  = iif(lC,"rg+/gb,gb/rg,n" , "n/w,w+/n,n")   && data entry fields
  303.     cl_Error = iif(lC,"rg+/r,w/n,n"    , "w+/n,n/w,n")   && error messages
  304.     cl_Entry = iif(lC,"n/w,w/n,n"      , "n/w,w/n,n")    && data entry??
  305.     cl_Stand = iif(lC,"w+/b,b/w,n"     , "w+/n,n/w,n")   && standard screen
  306.     cl_Menu  = iif(lC,"rg+/b,b/w,n"    , "w+/n,n/w,n")   && menus
  307.     cl_Warn  = iif(lC,"rg+/r,w/n,n"    , "w/n,n/w,n")    && warning messages
  308.     save to color all like cl_*        && create COLOR.MEM
  309.     
  310.     *-- change current color settings to these ...
  311.     set color to &cl_stand             
  312.     cTemp = extrclr("&cl_data")
  313.     set color of fields   to &cTemp
  314.     set color of messages to &cTemp
  315.     set color of box      to &cTemp
  316.     cTemp = extrclr("&cl_stand")
  317.     set color of highlight to &cTemp
  318.     
  319. RETURN
  320. *-- EoP: SetColor2
  321.  
  322. FUNCTION ExtrClr
  323. *-------------------------------------------------------------------------------
  324. *-- Programmer..: Ken Mayer (CIS: 71333,1030)
  325. *-- Date........: 05/24/1991
  326. *-- Notes.......: Used to extract the first parameter of the MEMVARS
  327. *--               created from SETCOLOR above. The SET COLOR OF commands can
  328. *--               only use the first parameter.
  329. *--               It is recommended that you run SetColor (above) first, 
  330. *--               although if you define your own color memvars, this will work
  331. *--               just as well.
  332. *-- Written for.: dBASE IV, 1.1
  333. *-- Rev. History: 05/24/1991 -- Original
  334. *-- Calls.......: None
  335. *-- Called by...: Any
  336. *-- Usage.......: extrclr(<cMemVar>)
  337. *-- Example.....: set color of highlight to &extrclr(cl_stand)
  338. *-- Returns.....: "W+/B"
  339. *-- Parameters..: cMemVar = color memory variable to have colors extracted from
  340. *-------------------------------------------------------------------------------
  341.     
  342.     parameters cMemVar
  343.     
  344. RETURN substr(cMemVar,1,(at(",",cMemVar)-1)) 
  345. *-- EoF: ExtrClr()
  346.  
  347. FUNCTION InvClr
  348. *-------------------------------------------------------------------------------
  349. *-- Programmer..: Ken Mayer (CIS: 71333,1030)
  350. *-- Date........: 05/23/1991
  351. *-- Notes.......: Used to set an inverse color, using value(s) returned
  352. *--               from extrclr above, or from a single color memvar.
  353. *--               Inverted colors may give odd results -- RG+ (yellow) is
  354. *--               not a background color, for example, and will appear as
  355. *--               RG (brown) -- this may not be what you wanted ...
  356. *-- Written for.: dBASE IV, 1.1
  357. *-- Rev. History: 05/23/1991 -- Original
  358. *-- Calls.......: None
  359. *-- Called by...: Any
  360. *-- Usage.......: invclr(<cMemVar>)
  361. *-- Example.....: set color of highlight to &invclr(extrclr(cl_stand))
  362. *--                    or
  363. *--               x = extrclr(cl_stand)
  364. *--               set color of highlight to &invclr(x)
  365. *-- Returns.....: "B/W+"
  366. *-- Parameters..: cMemVar = color variable containing colors to be inverted
  367. *-------------------------------------------------------------------------------
  368.  
  369.     parameters cMemVar
  370.     private cTemp1, cTemp2
  371.     
  372.         cTemp1 = substr(cMemVar,1,(at("/",cMemVar)-1))
  373.         cTemp2 = substr(cMemVar,(at("/",cMemVar)+1),len(cMemVar))
  374.  
  375. RETURN cTemp2+"/"+cTemp1
  376. *-- EoF: InvClr()
  377.  
  378. **********************************************************************
  379. ***** THE FOLLOWING WERE MOVED HERE FROM OTHER LIBRARY FILES FOLLOWING
  380. ***** THE RELEASE OF dBASE IV, 2.0.  KJM
  381. **********************************************************************
  382.  
  383. FUNCTION Rat
  384. *-------------------------------------------------------------------------------
  385. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  386. *-- Date........: 03/01/1992
  387. *-- Notes.......: Reverse "at", returns position a character string is last
  388. *--               AT in a larger string.
  389. *-- Written for.: dBASE IV
  390. *-- Rev. History: 03/01/1992 -- Original Release
  391. *-- Calls.......: None
  392. *-- Called by...: Any
  393. *-- Usage.......: Rat("<cFindStr>","<cBigStr>")
  394. *-- Example.....: ? Rat("Test","This is a Test string, with Test data")
  395. *-- Returns.....: Numeric value
  396. *-- Parameters..: cFindStr = string to find in cBigStr
  397. *--               cBigStr  = string to look in
  398. *-------------------------------------------------------------------------------
  399.  
  400.     parameters cFindstr, cBigstr
  401.     private nPos,nLen
  402.     nLen = len( cFindstr )
  403.     nPos = len( cBigstr ) - nLen + 1
  404.     do while nPos > 0
  405.         if substr( cBigstr, nPos, nLen ) = cFindstr
  406.             exit
  407.         else
  408.             nPos = nPos - 1
  409.         endif
  410.     enddo
  411.     
  412. RETURN max( nPos, 0 )
  413. *-- EoF: RAt()
  414.  
  415. FUNCTION IsMouse
  416. *-------------------------------------------------------------------------------
  417. *-- Programmer..: Ken Mayer (CIS: 71333,1030)
  418. *-- Date........: 06/18/1992
  419. *-- Notes.......: This is used to determine the presence of a mouse driver.
  420. *--               Returns a .t. if a mouse driver is detected, a .f. otherwise.
  421. *--               This routine will turn the mouse off, automatically. This
  422. *--               can be used to detect a mouse, and turn it off, as well
  423. *--               as to set a memvar to determine the current mouse state.
  424. *--               For example, after running this routine, the mouse will be
  425. *--               off (if there's a driver).
  426. *--               ******************************
  427. *--               **** REQUIRES JPMOUSE.BIN ****
  428. *--               ******************************
  429. *-- Written for.: dBASE IV, 1.5
  430. *-- Rev. History: 06/18/1992 -- Original
  431. *-- Calls.......: None
  432. *-- Called by...: Any
  433. *-- Usage.......: IsMouse()
  434. *-- Example.....: ?IsMouse()
  435. *-- Returns.....: Logical
  436. *-- Parameters..: None
  437. *-------------------------------------------------------------------------------
  438.  
  439.     private cRetVal, lIsMouse, X
  440.     
  441.     Load JPMOUSE.BIN
  442.     cRetVal = call("JPMOUSE","?")
  443.     lIsMouse = iif(cRetVal="T",.t.,.f.)
  444.     if lIsMouse
  445.         x = call("JPMOUSE","H")
  446.     endif
  447.     release module JPMOUSE
  448.  
  449. RETURN lIsMouse
  450. *-- EoF: IsMouse()
  451.  
  452. PROCEDURE SetMouse
  453. *-------------------------------------------------------------------------------
  454. *-- Programmer..: Ken Mayer (CIS: 71333,1030)
  455. *-- Date........: 06/18/1992
  456. *-- Notes.......: This is used to determine the presence of a mouse driver,
  457. *--               and/or turn the mouse cursor off in dBASE IV, 1.5
  458. *--               ******************************
  459. *--               **** Requires JPMOUSE.BIN ****
  460. *--               ******************************
  461. *-- Written for.: dBASE IV, 1.5
  462. *-- Rev. History: 06/18/1992 -- Original
  463. *-- Calls.......: None
  464. *-- Called by...: Any
  465. *-- Usage.......: Do SetMouse with <c_Mouse>
  466. *-- Example.....: PUBLIC c_Mouse
  467. *--               x=ismouse()  && function in MISC.PRG
  468. *--               store "OFF" to c_Mouse  && after calling IsMouse() it's 'Off'
  469. *--               ON KEY LABEL Alt-M DO SetMouse
  470. *-- Returns.....: .T.
  471. *-- Parameters..: c_Mouse = A GLOBAL memory variable -- this can/will be changed
  472. *--                         by this procedure to the opposite scenario when the
  473. *--                         routine is called. The concept here is to switch
  474. *--                         the mouse on and/or off if there's a mouse driver.
  475. *--                This memvar should be set to the current status of the mouse-
  476. *--                if on, it should hold "ON" in it ...
  477. *-------------------------------------------------------------------------------
  478.  
  479.     private X
  480.     
  481.     if type("C_MOUSE") # "C"         && if c_Mouse has not been defined as
  482.         return                        &&   a character field, return
  483.     endif
  484.     
  485.     load JPMOUSE.BIN                && load the module
  486.     
  487.     *-- if the mouse is off, we're going to set it on ("S"), if on, we're
  488.     *-- going to set it off "H")
  489.     cSetMouse = iif(upper(c_Mouse) = "OFF","S","H") 
  490.     x=call("JPMOUSE",cSetMouse)      
  491.     
  492.     release module JPMOUSE           && remove from memory
  493.     
  494.     *-- if c_Mouse was 'off' we are setting it 'on', and vice versa
  495.     c_Mouse = iif(upper(c_Mouse) = "OFF","ON","OFF") && change state of c_Mouse
  496.  
  497. RETURN
  498. *-- EoP: SetMouse
  499.  
  500. FUNCTION IsUnique
  501. *********************************************************************
  502. **                ** WARNING WARNING WARNING **
  503. ** Extensive testing has shown that this routine causes problems in
  504. ** dBASE IV, 1.5 and later. Use SEEK() or SEEK  instead, to determine
  505. ** uniqueness (if FOUND() and all that ...)
  506. **********************************************************************
  507. *-------------------------------------------------------------------------------
  508. *-- Programmer..: Clinton L. Warren (VBCES)
  509. *-- Date........: 04/28/1992
  510. *-- Notes.......: Checks to see if an index key already exists in the current
  511. *--               selected database. This function was inspired by Tom
  512. *--               Woodward's Chk4Dup UDF.
  513. *-- Written for.: dBASE IV, 1.1
  514. *-- Rev. History: May 15, 1991 Version 1.1  Added check for zero record database
  515. *--               May  7, 1991 Version 1.0  Initial 'release'.
  516. *--               04/28/1992 -- modified for dBASE IV, 1.5 due to 'new'
  517. *--               behavior (see READ.ME that comes with 1.5). Should function
  518. *--               fine with 1.1 and 1.0. This change from David Love (DAVIDLOVE).
  519. *--               NOTE: NEW PARAMETER
  520. *-- Calls.......: None
  521. *-- Called by...: Any
  522. *-- Usage.......: IsUnique(<xValue>,"<cOrder>","<cField>")
  523. *-- Example.....: @5,5 SAY "SSN: " GET SSN PICTURE "999-99-9999";
  524. *--                  valid required IsUnique(SSN, "SSN", "SSN");
  525. *--                  message "Enter a new SSN";
  526. *--                  error chr(7)+"SSN must be unique!"
  527. *-- Returns.....: .T./.F.
  528. *-- Parameters..: xValue = Value (any non-memo type) to check for uniqueness
  529. *--               cOrder = MDX Tag used to order the database. Must be set for
  530. *--                        field being checked.
  531. *--               cField = field name for 'get'.
  532. *-------------------------------------------------------------------------------
  533.     
  534.     parameters xValue, cOrder, cField
  535.     private nRecNo, nRecCnt, cSetNear, cSetDel, lIsDeleted, cSetOrder
  536.     private lIsUnique
  537.     
  538.     nRecNo = recno()           && store current record number
  539.     nRecCnt = reccount()       && count records in database
  540.     
  541.     if nRecCnt = 0             && empty database, cValue MUST be unique
  542.        return .t.
  543.     endif
  544.     
  545.     cSetNear = set('NEAR')     && store status of NEAR flag
  546.     set near off               && set it off
  547.     cSetDel = set('DELETE')    && store status of DELETE
  548.     set delete on              && Delete must be ON for this to work
  549.     lIsDeleted = deleted()     && is current record deleted?
  550.     delete                     && set delete flag for current record
  551.     cSetOrder = order()        && store current MDX tag
  552.     set order to (cOrder)      && set tag to that sent to function
  553.     
  554.     if seek(xValue)            && does it exist already?
  555.        lIsUnique = .f.         &&   if so, it's not unique
  556.     else                       && otherwise,
  557.        lIsUnique = .t.         &&   it is.
  558.     endif
  559.    
  560.    set order to (cSetOrder)   && restore changed settings to original settings
  561.    set delete &cSetDel
  562.    set near &cSetNear
  563.    
  564.    if nRecNo > nRecCnt        && if called during an append
  565.       go bottom               && goto the bottom of the database,
  566.       skip 1                  &&   plus one record (the new one)
  567.       if lIsUnique            && this is the new part ...
  568.      replace &cField with xValue
  569.       endif
  570.    else
  571.       go nRecNo               && otherwise, goto the current record number
  572.    endif
  573.  
  574.    if .not. lIsDeleted        && was record 'deleted' before?
  575.       recall                  && if not, undelete it ... (turn flag off)
  576.    endif 
  577.  
  578. RETURN (lIsUnique)
  579. *-- EoF: IsUnique()
  580.  
  581. FUNCTION Delay
  582. *-------------------------------------------------------------------------------
  583. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  584. *-- Date........: 03/01/1992
  585. *-- Notes.......: Delay Loop.  Returns .T. after lapse of given number of 
  586. *--               seconds.  Accurate to one second.  For dBASE IV 2.0, use
  587. *--               the upgraded version in Time.prg.
  588. *--               This may be used in conjunction with EXACTIME.BIN or a
  589. *--               similar routine that obtains the tick count.  In that case,
  590. *--               the delay may be made accurate to one tick.  To use it this
  591. *--               way, add:
  592. *--                             LOAD Exactime
  593. *--                             Arg = space(11)
  594. *--               and substitute for each call of the time() function:
  595. *--                             call( "Exactime", Arg )
  596. *--
  597. *-- Written for.: dBASE IV, Versions below 2.0
  598. *-- Rev. History: 03/01/1992 -- Original function
  599. *--               04/20/1993 -- modified to deal with fractions, bug fixed
  600. *-- Calls.......: TIME2SEC()           Function in TIME.PRG
  601. *-- Called by...: Any
  602. *-- Usage.......: Delay(<nSeconds>)
  603. *-- Example.....: lX= Delay(10.25)
  604. *-- Returns.....: Logical
  605. *-- Parameters..: nSeconds = number of seconds to delay
  606. *-------------------------------------------------------------------------------
  607.  
  608.         parameters nSeconds         && up to 86400, one day
  609.         private nTimeout, nTimenow, lRollover
  610.         nTimeout = 100 * ( Time2Sec( time() ) + nSeconds )
  611.         if nTimeout > 8640000
  612.           lRollover = .T.
  613.           nTimeout = nTimeout - 8640000
  614.         else
  615.           lRollover = .F.
  616.         endif
  617.         do while .T.
  618.           nTimenow = 100 * Time2Sec( time() )
  619.           if nTimenow < nTimeout
  620.             lRollover = .F.
  621.           else
  622.             if .not. lRollover
  623.               exit
  624.             endif
  625.           endif
  626.         enddo
  627.  
  628. RETURN .T.
  629. *-- EoF: Delay()
  630.  
  631. *-------------------------------------------------------------------------------
  632. *-- End of Program: OBSOLETE.PRG
  633. *-------------------------------------------------------------------------------
  634.