Atten: Larry Serflaten - Re: Dictionary Questions, Questions, Questions 
Author Message
 Atten: Larry Serflaten - Re: Dictionary Questions, Questions, Questions

Your code wetted my apitite to re-visit an old project that has been
on the back burner for a couple years now.
I have a larger word list now (thanks to Moby) that contains 350k+
records. (my old one had 175k+)
It also contains characters other than A-Za-z and I would like to use
these also.
Note: VB is just a hobby of mine so I'm no pro at it.
ReDim myWords(676 To 18278)
Can you explain why you used the OddBall dim's here?
Will all words in my list equate with in this range?
Function GetValue:
How can I expand this to use other characters besides just A-Za-z?
I'm using the RichText control because the List control blows its cool
somewhere in the 's' range even with my old list ;( and it really
takes a lot of time to load so I need some help on how to read the
file X number of records before and after the word. The word list is
just a sequential file using vbCRLF delimiters.
Would there be a way to store the information in the collection to a
file so it wouldn't have to be re-built each time?
Hope this makes sense to you...

Wow!! I have others but they can wait or they'll get answered in the
process... LOL

Any and All Help is Appreciated..


'[ Form1 code ]
Private Dict As WordList

Private Sub Command1_Click()
  ' Add only returns true for the first occurance.
  ' Adding the same word more than once does nothing new.
  If Dict.Add(Text1.Text) Then
    List1.AddItem LCase$(Text1.Text)
  End If
End Sub

Private Sub Command2_Click()
  MsgBox Dict.Find(Text1.Text), vbOKOnly, UCase$(Text1.Text)
End Sub

Private Sub Form_Load()
Dim i
  Set Dict = New WordList
  Text1 = ""
  Command1.Caption = "Add"
  Command2.Caption = "Find"

  'Preload some words
  For Each i In Array("bat", "bats", "cat", "cats", _
                       "rat", "rats", "drat", "drats", _
                       "necessary", "electrocephalograph")
    Dict.Add CStr(i)
    List1.AddItem i
End Sub

'[ WordList code ]
Option Explicit
' Yes/No Dictionary object
' ? 2002 Larry Serflaten
' (There's so little code here, surely comments aren't necessary!  ;-)

' Only allocated when needed.
Private myWords() As WordList
Private myAllocated As Boolean

Public Active As Boolean

Public Function Add(ByRef Item As String) As Boolean
Dim Value As Integer
  If Valid(Item) Then
    If Len(Item) Then
      ' Make room
      If Not myAllocated Then
        ReDim myWords(676 To 18278)
        myAllocated = True
      End If
      Value = GetValue(Item)
      ' Only if necessary....
      If myWords(Value) Is Nothing Then
         Set myWords(Value) = New WordList
      End If
       Add = myWords(Value).Add(Mid$(Item, 4))
      Add = Not Active
      Active = True
    End If
  End If
End Function

Public Function Find(ByRef Item As String) As Boolean
  'Only American alphabet allowed (this version)
  If Valid(Item) Then
    Find = Search(LCase$(Item))
  End If
End Function

Friend Function Search(ByRef Item As String) As Boolean
Dim Value As Integer
  Value = GetValue(Item)
  If Len(Item) > 3 Then
    Search = myWords(Value).Search(Mid$(Item, 4))
    If myAllocated Then
      If Not myWords(Value) Is Nothing Then
        Search = myWords(Value).Active
      End If
    End If
 End If
End Function

Private Function GetValue(ByRef Item As String) As Integer
Dim Ascii() As Byte
    Ascii = Left$(Item, 3) & "```"
    GetValue = (Ascii(4) - 96) _
             + (Ascii(2) - 96) * 26 _
             + (Ascii(0) - 96) * 26 * 26
End Function

Private Function Valid(ByRef Item) As Boolean
  If Not Item Like "*[!A-Za-z]*" Then
    Valid = True
    MsgBox "Invalid characters in word: " & UCase$(Item)
  End If
End Function

Have a good day...


Thu, 10 Mar 2005 00:57:04 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Larry Serflaten, are you still there, somewhere?

2. Attn: Larry Serflaten

3. Question about Larry Rebich's ShellAndWait

4. Hard Question (Larry, Michael ???) - MAC Addresses

5. questions,questions,questions.

6. Questions!Questions!Questions

7. Questions Questions Questions


9. Another Scripting Dictionary question

10. Question: Pop-up dictionary

11. Question on Dictionary objects and SQL

12. simple question about dictionary object


Powered by phpBB® Forum Software