'ask for a filename filedialog "Select a text file", "*.TXT", filename$ 'if filename$ = "" then the user canceled the file selection if filename$ = "" then end open filename$ for input as #aol DIM searchterms$(50000) NumTerms = 0 WHILE NOT (eof(#aol)) NumTerms = NumTerms + 1 line input #aol, searchterms$(NumTerms) WEND close #aol DIM words$(100000) DIM usecounter(100000) DIM parse$(100) DIM counter(100) WordCounter = 0 unique = 1 FOR i = 1 to NumTerms WordNum = 1 lastword = 0 counter(1) = 0 FOR letter = 1 to LEN(searchterms$(i)) IF letter = LEN(searchterms$(i)) THEN lastword = 1 : GOSUB [WordParser] IF (MID$(searchterms$(i), letter, 1) = " " AND letter < LEN(searchterms$(i))) THEN GOSUB [WordParser] counter(WordNum) = counter(WordNum) + 1 NEXT letter NEXT i FOR i = 1 to unique print words$(i), usecounter(i) NEXT i END [WordParser] offset = 0 IF (MID$(searchterms$(i), letter, 1) = " " AND NOT(WordNum = 1)) THEN offset = 1 parse$(WordNum) = MID$(searchterms$(i), (letter-counter(WordNum)+offset+lastword), counter(WordNum) + lastword) ' cut off the last space if it exists IF RIGHT$(parse$(WordNum), 1) = " " THEN parse$(WordNum) = MID$(searchterms$(i), (letter-counter(WordNum)+offset+lastword), counter(WordNum) + lastword - 1) GOSUB [Lookup] WordNum = WordNum + 1 counter(WordNum) = 0 RETURN [Lookup] ' I realize that this is a stupid way to use a lookup table, searching the whole thing. Of couse I should have a tree search, ' where I just search words of the same length, and then just words that start with the same letter and so on. But I set out to ' do this all in an hour and I ran out of time. found = 0 h = 1 WHILE (found = 0 AND h <= unique) IF parse$(WordNum) = words$(h) THEN usecounter(h) = usecounter(h) + 1 : found = 1 h = h + 1 WEND IF found = 0 THEN GOSUB [add] RETURN [add] words$(unique+1) = parse$(WordNum) unique = unique + 1 print unique usecounter(unique) = 1 RETURN