Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding word in memo field 2

Status
Not open for further replies.

Center

Programmer
Oct 19, 2002
52
US
Often I search fields for a word, using this way: List for 'the word'$fieldname.
That does not work in memo fields. Could you give me the correct way to write such a search for a memo field?
Thanks.
Am using dbase4 for Dos.
 
Excuse me for a bad "post." Of course it works fine from command line, my problem was when I did it in programs.
 
You can't search a memo field that way. The limit you're facing is that dBase (at least up through dBase for DOS version 5) has a string length limit of 254 characters which is also the maximum size for a character field. Of course memo fields can hold text much longer than that! Hopefully your version of dBase has the SET MEMOWIDTH command and the MEMLINES() and MLINE() functions.

Here is a sample program that should work. You'll notice that I'm examining two lines at a time. That's because your search text could be two or more words and you might miss a valid match if the phrase was split across two lines. I'll leave it to you to adjust it for any other specific issues. (What other issues? Well, what if there are carriage returns and line feeds in the memo field? Do you want to ignore upper and lower case differences? Do you need to count the number of matches? Do you need to know the location in the memo field?)
Code:
PROCEDURE IsInMemo
PARAMETERS memField, strFind
PRIVATE x, wasFound, oldWidth, nTot, strPart
wasFound = .F.
oldWidth = SET("MEMOWIDTH")
SET MEMOWIDTH TO 70  && do not exceed 126 (126+1+126=253 chars)
mTot = MEMLINES(&memField)
FOR x = 1 TO mTot
   strPart = MLINE(&memField, x)
   IF " " $ strFind .AND. x+1 <= mTot
      * combine 2 lines to search for multi-word
      * insert space that MLINE() may have removed
      strPart = strPart+" "+MLINE(&memField, x+1)
   ENDIF
   IF strFind $ strPart
      wasFound = .T.
      EXIT
   ENDIF
NEXT
SET MEMOWIDTH TO &oldWidth

RETURN wasFound
dbMark
 
I'm not too familiar with dBase IV so this may not work. In dBase III+, in order to manipulate memo fields, you had to turn them into a line, so to speak, using the memoline() funtion. Memoline() has 3 parameters: the memofield name, the length of the "line" (an integer value from 4-254), and the line number. (The default is 1 and the total number of lines is derived by dividing the total length of the memofield by the length of the line (parameter #2). There is a function called mlcount() that can do this for you - mlcount(memofield_name,length of line).

So, you can set up a for/next or do/while loop to cylce through a lengthy memofield like this:

for x = 1 to mlcount(memofield,70)
y = memoline(memofield,70,x)
z = at("word_to_find",y)
if z > 0
?? "word found"
endif
next

I hope this helps in some way.


There's always a better way. The fun is trying to find it!
 
Oh, no. I jumped in with all 4 feet! What a splash! You're right, "$" should work. What does you program code look like? How is it different from the command line?

Is it possible you're using a variable to identify the field? If so, try using either EVAL(varMemo) or &varMemo in the test.
 
Yes am using a Memory Variable (to do UPPER, just in case) when put in a program, but using the actual name when I do from command line.
 
You cannot use UPPER(memoField) as it is not supported for use with memo fields. [Notice that LEN(memoField) does work!] Likely you will have to parse it out section by section as shown above if the length of the memo field is over 254 characters. If it is 254 or fewer characters you can place the memo field into a variable for the UPPER(myVariable) test.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top