home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
01e
/
miscfunc.zip
/
STRGFUNC.PRG
< prev
Wrap
Text File
|
1988-04-12
|
5KB
|
128 lines
*************************************************************************
** STRGFUNC.PRG - variety of QS string functions
**
** Copyright Steve Titterud 1987
** 2157 Glenridge Ave.
** St. Paul, MN 55119
** (612)-739-7229
** Permission for non-commercial use granted.
**
** lfpad(string,character,length)
** - pads string on left with character to length
** rtpad(string,character,length)
** - pads string on right with character to length
** bothpad(string,left character,right character,length)
** - pads string on left with left character, and on
** right with right character, to length
** betwpad(string,string,character,length)
** - pads between 2 strings with character to length
** fldcount(datafile)
** - calculates # of fields in .dbf in current work area
** strint(number)
** - returns number as string, left-trimmed
** makestr(object) && borrowed from another author
** - returns string representation of any data type
**
**
*************************************************************************
FUNCTION lfpad
PARAMETERS before,char,length
PRIVATE after
** pads variable before on left with character char to length length
after=replicate(char,(length-len(before)))+before
RETURN after
************************************************************************
FUNCTION rtpad
PARAMETERS before,char,length
PRIVATE after
** pads variable before on right with character char to length length
after=before+replicate(char,(length-len(before)))
RETURN after
************************************************************************
FUNCTION bothpad
PARAMETERS before,lchar,rchar,length
PRIVATE after,frontpad,backpad
** pads variable before both fore and aft with character char to length length
frontpad=int((length-len(before))/2)
backpad=(length-len(before)-frontpad)
after=replicate(lchar,frontpad)+before+replicate(rchar,backpad)
RETURN after
************************************************************************
FUNCTION btwnpad
PARAMETERS str1,str2,char,length
PRIVATE after
** pads between str1 and str2 with character char to length length
after=str1+replicate(char,(length-(len(str1)+len(str2))))+str2
RETURN after
************************************************************************
FUNCTION fldcount
PRIVATE finalnum,fldmax,fldmin,thisfld,gotit
** returns number of fields in datafile structure
** datafile presumed to be open and selected, and to not be empty
** we're actually looking for a field index that exists which is followed
** by one that does NOT exist!
fldmax=128
fldmin=1
thisfld=fldmax
finalnum=0
if type(field(thisfld))<>"U"
** it's 128
gotit=.T.
finalnum=128
else
**it's smaller - is it 1?
if type(field(2))="U"
finalnum=1
gotit=.T.
else
gotit=.F.
thisfld=int(thisfld/2) && set to 64
endif
endif
do while .not. gotit
if type(field(thisfld))="U"
** it's smaller
fldmax=thisfld-1 && unless exit at next step, can't be any bigger
if type(field(thisfld-1))<>"U"
** this is it!
finalnum=thisfld-1
gotit=.T.
else && this isn't it; gotta go down
thisfld=thisfld-int((thisfld-fldmin)/2) && split difference from min
endif
else
** field(thisfld) exists; finalnum might be bigger, or this might be it
fldmin=thisfld+1 && unless exit at next step, can't be any smaller
if type(field(thisfld+1))="U"
** this is it!
finalnum=thisfld
gotit=.T.
else
** this isn't it; gotta go up
thisfld=thisfld+int((fldmax-thisfld)/2) && split difference from max
endif
endif
enddo
RETURN finalnum
************************************************************************
FUNCTION strint
PARAMETERS number
RETURN ltrim(str(int(number)))
************************************************************************
FUNCTION make_str
PARAMETERS object
PRIVATE answer,thistype
thistype=TYPE("object")
DO CASE
CASE thistype="D"
answer=DTOC(object)
CASE thistype="N"
answer=STR(object)
CASE thistype="L"
answer=iif(object,"Y","N")
OTHERWISE
answer=object
ENDCASE
RETURN answer
************************************************************************