A useful little tool for anyone who likes to play Scrabble.
Download and extract the word list/dictionary from below to use with this program.
Code: (Select All)
file$ = "Collins Scrabble Words (2019) with definitions.txt"
'279498 words
Type Dict_Type
word As String
definition As String
End Type
ReDim As String Word(1000000), Definition(1000000)
Open file$ For Binary As #1
Do Until EOF(1)
Line Input #1, text$
count = count + 1
p = InStr(text$, Chr$(9))
Word(count) = _Trim$(Left$(text$, p - 1))
Definition(count) = _Trim$(Mid$(text$, p + 1))
Loop
ReDim _Preserve Word(count) As String
ReDim _Preserve Definition(count) As String
Do
Color 4
Input "Give me a word to look up for you =>"; word$
If word$ = "" Then System
i = BinaryStringSearch(UCase$(word$), Word())
Color 15
Print
If i > -1 Then
Print word$; " found! It's definition is: "; Definition(i)
Else
Print word$; " doesn't exist! You big dummy! Cheater! Who's gonna play Scrabble with you?!!"
End If
Print
Loop
Function BinaryStringSearch (search$, Array() As String)
'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
'When the search string is found, it'll return a value = to the index proper.
'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex
BinaryStringSearch = BinaryStringSearchSome(search$, Array(), LBound(Array), UBound(Array))
End Function
Function BinaryStringSearchSome (search$, Array() As String, StartIndex As Long, EndIndex As Long)
'These routines work with actual indexes, so we can search from Array(-10 to 10), if we want to.
'When the search string is found, it'll return a value = to the index proper.
'When it's not found, it'll return a value LESS THAN the LBOUND limit of the array,
'And the point where the string WOULD'VE appeared, if it existed, is after the shared variable LastIndex
min = StartIndex
max = EndIndex
Do
gap = (max + min) \ 2
compare = _StrCmp(search$, Array(gap))
If compare > 0 Then
min = gap + 1
ElseIf compare < 0 Then
max = gap - 1
Else
BinaryStringSearchSome = gap
Exit Function
End If
If max - min < 1 Then
If search$ = Array(min) Then
BinaryStringSearchSome = min
Else
BinaryStringSearchSome = LBound(Array) - 1
If search$ < Array(min) Then
LastIndex = min - 1
Else
LastIndex = min
End If
End If
found = -1
End If
Loop Until found
End Function
Download and extract the word list/dictionary from below to use with this program.