home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / miscfunc.zip / STRGFUNC.PRG < prev   
Text File  |  1988-04-12  |  5KB  |  128 lines

  1. *************************************************************************
  2. **  STRGFUNC.PRG - variety of QS string functions
  3. **
  4. **  Copyright Steve Titterud 1987
  5. **            2157 Glenridge Ave.
  6. **            St. Paul, MN 55119
  7. **            (612)-739-7229
  8. **            Permission for non-commercial use granted.
  9. **
  10. **               lfpad(string,character,length)
  11. **                     - pads string on left with character to length
  12. **               rtpad(string,character,length)
  13. **                     - pads string on right with character to length
  14. **             bothpad(string,left character,right character,length)
  15. **                     - pads string on left with left character, and on
  16. **                       right with right character, to length
  17. **             betwpad(string,string,character,length)
  18. **                     - pads between 2 strings with character to length
  19. **            fldcount(datafile)
  20. **                     - calculates # of fields in .dbf in current work area
  21. **              strint(number)
  22. **                     - returns number as string, left-trimmed
  23. **             makestr(object)  && borrowed from another author
  24. **                     - returns string representation of any data type
  25. **
  26. **
  27. *************************************************************************
  28. FUNCTION lfpad
  29. PARAMETERS before,char,length
  30. PRIVATE after
  31. ** pads variable before on left with character char to length length
  32. after=replicate(char,(length-len(before)))+before
  33. RETURN after
  34. ************************************************************************
  35. FUNCTION rtpad
  36. PARAMETERS before,char,length
  37. PRIVATE after
  38. ** pads variable before on right with character char to length length
  39. after=before+replicate(char,(length-len(before)))
  40. RETURN after
  41. ************************************************************************
  42. FUNCTION bothpad
  43. PARAMETERS before,lchar,rchar,length
  44. PRIVATE after,frontpad,backpad
  45. ** pads variable before both fore and aft with character char to length length
  46. frontpad=int((length-len(before))/2)
  47. backpad=(length-len(before)-frontpad)
  48. after=replicate(lchar,frontpad)+before+replicate(rchar,backpad)
  49. RETURN after
  50. ************************************************************************
  51. FUNCTION btwnpad
  52. PARAMETERS str1,str2,char,length
  53. PRIVATE after
  54. ** pads between str1 and str2 with character char to length length
  55. after=str1+replicate(char,(length-(len(str1)+len(str2))))+str2
  56. RETURN after
  57. ************************************************************************
  58. FUNCTION fldcount
  59. PRIVATE finalnum,fldmax,fldmin,thisfld,gotit
  60. ** returns number of fields in datafile structure
  61. ** datafile presumed to be open and selected, and to not be empty
  62. ** we're actually looking for a field index that exists which is followed
  63. ** by one that does NOT exist!
  64. fldmax=128
  65. fldmin=1
  66. thisfld=fldmax
  67. finalnum=0
  68. if type(field(thisfld))<>"U"
  69.    ** it's 128
  70.    gotit=.T.
  71.    finalnum=128
  72. else
  73.    **it's smaller - is it 1?
  74.    if type(field(2))="U"
  75.       finalnum=1
  76.       gotit=.T.
  77.    else
  78.       gotit=.F.
  79.       thisfld=int(thisfld/2)  && set to 64
  80.    endif
  81. endif
  82. do while .not. gotit
  83.    if type(field(thisfld))="U"
  84.       ** it's smaller
  85.       fldmax=thisfld-1  && unless exit at next step, can't be any bigger
  86.       if type(field(thisfld-1))<>"U"
  87.          ** this is it!
  88.          finalnum=thisfld-1
  89.          gotit=.T.
  90.       else  && this isn't it; gotta go down
  91.          thisfld=thisfld-int((thisfld-fldmin)/2)  && split difference from min
  92.       endif
  93.    else
  94.       ** field(thisfld) exists; finalnum might be bigger, or this might be it
  95.       fldmin=thisfld+1  && unless exit at next step, can't be any smaller
  96.       if type(field(thisfld+1))="U"
  97.          ** this is it!
  98.          finalnum=thisfld
  99.          gotit=.T.
  100.       else
  101.          ** this isn't it; gotta go up
  102.          thisfld=thisfld+int((fldmax-thisfld)/2)  && split difference from max
  103.       endif
  104.    endif
  105. enddo
  106. RETURN finalnum
  107. ************************************************************************
  108. FUNCTION strint
  109. PARAMETERS number
  110. RETURN ltrim(str(int(number)))
  111. ************************************************************************
  112. FUNCTION make_str
  113. PARAMETERS object
  114. PRIVATE answer,thistype
  115. thistype=TYPE("object")
  116. DO CASE
  117.    CASE thistype="D"
  118.       answer=DTOC(object)
  119.    CASE thistype="N"
  120.       answer=STR(object)
  121.    CASE thistype="L"
  122.       answer=iif(object,"Y","N")
  123.    OTHERWISE
  124.       answer=object
  125. ENDCASE
  126. RETURN answer
  127. ************************************************************************
  128.