' Dictionary_Search.iwb

AUTODEFINE "off"

DEF i, j, fnd, done=0, max, precs, rlen=0, wlen=0:INT
DEF pDb, pStmt:POINTER
DEF c, cq, qcq, qc, q, t:STRING
DEF dbName, error, path, recin, stmt, wword:STRING
DEF hrecin[50]:ISTRING
DEF c1:STRING

c = ","
q = "'"
cq = c + q
qcq = q + c + q
qc = q + c
t = "\t"

path = Getstartpath
dbName = path + "Dictionary.MDB"
OPENCONSOLE
pDb = dbConnect("Microsoft Access Driver (*.mdb)",dbName,";")
IF pDb = 0
	PRINT "(27) Error connecting"
	GOTO aborted
ENDIF
WHILE (done = 0)
	INPUT "Valid Chars: ", recin
'	recin = "LPSAKODNAONO"
	IF recin = ""
		done = 1
		GOTO endloop
	ENDIF
	CLS
	recin = LCASE$(recin)
	wlen = LEN(recin)
	max = 80 / (wlen+1)
	PRINT "Valid Chars: ", recin, " ", wlen, " ", max

	stmt = "SELECT COUNT(*) FROM DICTIONARY WHERE WLEN=" + LTRIM$(STR$(wlen))
	pStmt = dbExecSQL(pDb,stmt)
	error = dbGetErrorCode(pStmt)
	IF LEN(error)
		PRINT "(99) Failed to SELECT DB Error ", error, "-", dbGetErrorText(pStmt)
		PRINT stmt
		GOTO aborted
	ENDIF
	rlen = LEN(recin)
	WHILE dbGet(pStmt)
		dbGetData(pStmt,1,wword)
		PRINT
		PRINT "COUNT(*) ", wword
		PRINT
	ENDWHILE
	
	stmt = "SELECT WWORD FROM DICTIONARY WHERE WLEN=" + LTRIM$(STR$(wlen))
	pStmt = dbExecSQL(pDb,stmt)
	error = dbGetErrorCode(pStmt)
	IF LEN(error)
		PRINT "(99) Failed to SELECT DB Error ", error, "-", dbGetErrorText(pStmt)
		PRINT stmt
		GOTO aborted
	ENDIF
	rlen = LEN(recin)
	precs = 0
	WHILE dbGet(pStmt)
		hrecin = recin
		fnd = 0
		dbGetData(pStmt,1,wword)
		FOR i = 1 TO wlen
			c1 = MID$(wword,i,1)
			FOR j = 0 to rlen-1
				IF c1 = hrecin[j]
					hrecin[j] = "."
					fnd++
					j = rlen
					IF fnd = wlen
						PRINT wword, " ",
						precs++
						IF precs = max
							PRINT
							precs = 0
						ENDIF
					ENDIF
				ENDIF
			NEXT j
		NEXT i
	ENDWHILE
	LABEL endloop
	PRINT
	PRINT
	dbFreeSQL(pStmt)
	pStmt = 0
ENDWHILE
GOTO eoj
LABEL aborted
PRINT "Aborted due to error"
LABEL eoj
dbFreeSQL(pStmt)
pStmt = 0
dbDisconnect(pDb)
pDb = 0
CLOSECONSOLE
END