Q(uick)BASIC Function: TEXTCOMP
Quick View
TEXTCOMP
A function that compares two text strings and returns a similarity score
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- TEXTCOMP(a$,b$)
Description/Parameter(s)
a$,b$ | Two strings whose relative order as they would be sorted by an ISAM index is compared. Only the first 255 characters are considered. |
- The comparison is not case sensitive ("A" is the same as "a"), and any trailing spaces are removed.
- TEXTCOMP uses the International Character Sort Order Tables for sorting international characters. See Appendix E in the BASIC Language Reference.
TEXTCOMP returns an integer value 1, 0, or -1, depending on the relative positions of a$ and b$ as they would be sorted by an ISAM index: | |
-1 | When a$ precedes b$. |
1 | When a$ follows b$. |
0 | When a$ is equivalent to b$. |
Example
The following example uses TEXTCOMP to compare titles in a table named BookStock and then prints each title that begins with the word QuickBASIC. Because the comparison performed by TEXTCOMP is not case-sensitive, all variations of titles whose first word is QuickBASIC will be printed.
Note: To run this program, you must load the ISAM TSR program PROISAM.EXE. Also, this program assumes files called BOOKS.MDB and BOOKLOOK.BI exist in the current directory. BOOKS.MDB is a sample ISAM file that SETUP copies to your disk.
'$INCLUDE: 'booklook.bi' 'RecStruct structure.
DIM BigRec AS RecStruct 'Define record variable.
OPEN "books.mdb" FOR ISAM Books "BookStock" AS 1 'Open the ISAM file.
SETINDEX 1, "TitleIndexBS" 'Set the index.
'Make first record with "quickbasic" as first word of title current.
SEEKGE 1, "quickbasic"
IF NOT EOF(1) THEN 'Quit if no match.
DO
IF EOF(1) THEN END 'Quit if end of table.
RETRIEVE 1, BigRec.Inventory 'Fetch record into BigRec.
'Compare retrieved record to "quickbasic" in same way comparisons
'are done by ISAM. If they don't compare equal, Quit program.
IF TEXTCOMP(LEFT$(BigRec.Inventory.Title, 10), "quickbasic") <> 0 THEN
END
END IF
LPRINT BigRec.Inventory.Title 'Print valid titles to
'the line printer.
MOVENEXT 1 'Make next record current.
LOOP
ELSE
PRINT "Sorry, SEEK for 'quickbasic' failed in BOOKS.MDB"
END IF
See also: