home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April B / Pcwk4b98.iso / Borland / Dbase50w / SAMPLES1.PAK / SAMPPROC.PRG < prev    next >
Text File  |  1994-08-02  |  2KB  |  77 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Sampproc.prg
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         6/94
  7. *
  8. *  UPDATED:      6/94
  9. *
  10. *  REVISION:     $Revision:   1.40  $
  11. *
  12. *  VERSION:      dBASE FOR WINDOWS 5.0
  13. *
  14. *  DESCRIPTION:  This is a general procedure file containing useful functions
  15. *                called by some of the sample programs.
  16. *
  17. *  PARAMETERS:   None
  18. *
  19. *  CALLS:        None
  20. *
  21. *  USAGE:        SET PROCEDURE TO Sampproc.prg
  22. *
  23. ********************************************************************************
  24. #include <Messdlg.h>
  25.  
  26. InformationMessage("Sampproc.prg is a procedure file used by the samples.","Info")
  27.  
  28. ********************************************************************************
  29. function FormatStr(string)
  30. *
  31. * Could have 0 or more parameters.
  32. * This function will replace occurrences of "%<n>" with the corresponding
  33. * parameter string.  It will also replace all occurrences of "\n" with a Carriage
  34. * Return, and all occurrences of "\t" with a Tab.
  35. *
  36. * Example: x = FormatStr("Hello \n %1", "World") &&prints Hello World on 2 lines
  37. ********************************************************************************
  38. #define ENTER  chr(13)
  39. #define TAB    chr(9)
  40. local i, strPos, strCnt, tmpStr
  41.  
  42. tmpStr = string
  43. for i = 2 to argc()    && while have something to search for
  44.    tmpStr = StrTran(tmpStr, "%" + ltrim(str(i - 1)), argv(i))
  45. next
  46. tmpStr = StrTran(tmpStr, "\n", ENTER)
  47. tmpStr = StrTran(tmpStr, "\t", TAB)
  48.  
  49. return tmpStr
  50.  
  51.  
  52. *******************************************************************************
  53. function StrTran(string,curStr,repStr)
  54. *
  55. * Replaces all occurrences of curStr in string with repStr
  56. *******************************************************************************
  57. local strPos, lenCurStr, tmpStr
  58. tmpStr = string
  59. lenCurStr = len(curStr)
  60. strPos = at(curStr,tmpStr)
  61. do while strPos > 0
  62.    tmpStr = stuff(tmpStr, strPos, lenCurStr, repStr)
  63.    strPos = at(curStr,tmpStr)
  64. enddo
  65. return tmpStr
  66.  
  67.  
  68.  
  69. *******************************************************************************
  70. procedure SetEnvironment
  71. *
  72. * Environment settings used by most samples
  73. *******************************************************************************
  74. set talk off
  75. set ldCheck off
  76.  
  77.