// The easiest way of using this file is to save the words to be entered into the dictionary in // 'new.txt' and when the prompt appears type 'file'. The rest will be done automatically. clear screen load_file() check() index() enter() if read_file = true then read_from_file() end if save() check() sys$ = system$("del c:\\progra~1\\scrabble\\dictionary") end sub insert(a$(), word$) local count, insert_here, n, size, start dim word$(arraysize(word$(), 1) + 1) size = arraysize(a$(), 1) repeat size = size - 1 until(word$(size) <> "") size = size + 1 count = size // search for the position where word$ will be inserted repeat count = count - 1 until(word$ > a$(count) or count = 0) insert_here = count + 1 // Know the position is known shift the contents of all elements up // one place for n = size - 1 to insert_here step - 1 a$(n + 1) = a$(n) next n // insert word$ a$(insert_here) = word$ if idx(asc(word$) - 65) = 0 index() end sub sub check() local err, n local last$, this$ clear screen last$ = word$(1) err = false for n = 2 to arraysize(word$(), 1) this$ = word$(n) if last$ = this$ then print last$, " = ", this$ err = true inkey$ end if last$ = this$ next n if err = true error "\nDuplicate words in dictionary!" end sub sub save() local finish, m, n, pos, size local lin$ size = arraysize(word$(), 1) unlock() open #1, "c:\\progra~1\\scrabble\\based.txt", "w" pos = 1 repeat lin$ = "" repeat lin$ = lin$ + word$(pos) + " " pos = pos + 1 until(len(lin$) >= 72 or pos = size + 1) print #1, trim$(lin$) until(pos = size + 1) close #1 lock() end end sub sub load_file() local count, n local tmp$ open #1, "c:\\progra~1\\scrabble\\based.txt", "r" while( ! eof(1)) input #1 tmp$ count = count + 1 wend seek 1, 0, "begin" dim word$(count) for n = 1 to count input #1 word$(n) next n close #1 end sub sub enter() local n, ori_size local lin$, w$ read_file = false // Flag indicating if LIST commmand is used orisize = count() clear screen print colour("yellow", "black"), "Enter new words or:\n'QUIT' to exit.\n'NUMBER' for the number of words in the dictionary.\n'EDIT' to remove a single word.\n'LIST' to read words from file." print "Number of words in dictionary = ", orisize repeat input w$ if w$ = "" or len(w$) = 1 continue w$ = upper$(w$) if w$ = "LIST" then read_file = true w$ = "QUIT" // set w$ so that this routine exits naturally end if if w$ = "NUMBER" then print "The original size of the dictionary was ", orisize, ". It is now ", count(), "." end if if w$ = "EDIT" edit() if letter(w$) and search(w$) = - 99 and len(w$) > 1 and w$ <> "NUMBER" and w$ <> "QUIT" and w$ <> "EDIT" then insert(word$(), w$) print "Entered ", w$ end if until(w$ = "QUIT") end sub sub read_from_file() local n, ori_size, stream,newsize local lin$, w$ orisize = count() clear screen print colour("yellow", "black"), "Loading word list from file." stream = open("new.txt", "r") if stream = 0 error "The word list should be in the same folder as this program and named 'new.txt'." while( ! eof(stream)) input #stream w$ if w$ = "" or len(w$) = 1 continue w$ = upper$(w$) if letter_no_output(w$) and search(w$) = - 99 and len(w$) > 1 then insert(word$(), w$) print "Entered ", w$ end if wend close stream newsize=count() print "Original size of dictionary = ", orisize print "New size of dictionary = ",newsize print "Words entered = ",newsize-orisize end sub sub letter(w$) local count, done for count = 1 to len(w$) if not(mid$(w$, count, 1) >= "A" and mid$(w$, count, 1) <= "Z") then print "Non-alphabetic character!" return false end if next count return true end sub sub letter_no_output(w$) local count, done for count = 1 to len(w$) if not(mid$(w$, count, 1) >= "A" and mid$(w$, count, 1) <= "Z") then return false end if next count return true end sub sub search(w$) local pos, stream, where local tmp$ pos = idx(asc(w$) - 65) repeat tmp$ = word$(pos) if w$ = tmp$ then where = pos return where end if pos = pos + 1 until(left$(tmp$, len(w$)) > w$ or pos = arraysize(word$(), 1) + 1) return - 99 end sub sub index() local n, size, tidx local tmp$, word$ dim idx(25) idx(0) = 0 tmp$ = "A" size = arraysize(word$(), 1) - 1 for n = 1 to size word$ = word$(n) if tmp$ <> left$(word$, 1) and word$ <> "" then idx(asc(word$) - 65) = n tmp$ = left$(word$, 1) end if next n end sub sub edit() local where local w$ input "Enter the word to be deleted " w$ w$ = upper$(w$) if ! letter(w$) return where = search(w$) if where = - 99 then print "Word not found!" return end if remove(w$, where) end sub sub remove(w$, where) local n, size size = arraysize(word$(), 1) for n = where + 1 to size word$(n - 1) = word$(n) next n word$(size) = "" index() print "Removed ", w$ end sub sub count() local size size = arraysize(word$(), 1) repeat size = size - 1 until(word$(size) <> "") return size end sub sub lock() local sys$ sys$ = system$("attrib +r based.txt") end sub sub unlock() sys$ = system$("attrib -r based.txt") end sub