Cardbox > Support > Knowledge Base ...

Extracting the indexed words from a field

The Text property of the Field object gives you direct access to the entire text of a field, indexed and unindexed words alike. If you want to get just the indexed words (and numbers and dates) from a field, there is no IndexedText property built in to Cardbox, but you can construct a macro that does the same thing.

The IndexedText function

Function IndexedText(fld) Dim x x=fld.TextWithIndex x=Replace(x,vbLf," ") x=Split(x," ") Dim i,n,nFound For i=LBound(x) To UBound(x) n=CountStars(x(i)) If (n AND 1) Then x(nFound)=Mid(x(i),n\2+2) : nFound=nFound+1 End If Next Dim y() Redim y(nFound-1) For i=0 to nFound-1 : y(i)=x(i) : Next IndexedText=Join(y," ") End Function Function CountStars(str) Dim i,n n=Len(str) For i=1 To n If Mid(str,i,1)<>"*" Then CountStars=i-1 : Exit Function Next CountStars=n End Function

This function is quite complex because it deals with every possible case and has been optimised to work fast with large fields; but essentially it uses the TextWithIndex property to get field data along with indexing information, then looks at each word and keeps only those that are marked as being indexed.

Testing the macro

You can test the macro by adding a line such as the following:

MsgBox IndexedText(Fields("FLDNAME"))

where you should replace FLDNAME with the name of the field whose indexed words you want to extract.

© 2016 Martin Kochanski
"Cardbox" is a registered trademark.
 Top of page