Results 1 to 9 of 9

Thread: Search Array List With Structure

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Massachusetts
    Posts
    48

    Search Array List With Structure

    Help Please---I'm a teacher and I wrote a program to help my students work on their reading skills--the gist of the problem is I have a a group of words being read into a structure then added to an array list--ReadWordList is the structure ReadWord is the array list. ---see snippet below

    While mReader1.Read
    With ReadWordList 'fill structure first
    .Item = mReader1.GetString(1) 'word
    .Sounds = mReader1.GetString(2) 'word divided into sounds
    .Syll = mReader1.GetString(3) 'word divided by syllables
    End With

    ReadWord.Add(ReadWordList) 'fill array list with structure
    End While

    I know the array list gets filled and can access the structure ---problem ---how do I search for a specific word in the ReadWord array list?

    I used the following function call but it won't work

    Function FindTheSeekWord(ByVal stWord As String) As String
    Dim i As Integer
    i = ReadWord.IndexOf(stWord)
    If i >= 0 Then
    Return ReadWord(i).sound
    Else
    MessageBox.Show("no Match")
    End If
    End Function

    any suggestions??

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I think you migh be making the job harder. If you are going to use an ArrayList, then you need a structure. Just read the words in the ArrayList, then you can go like this

    VB Code:
    1. If (ReadWord.Contains("Word")) Then
    2.     MessageBox.Show("Word found")
    3. End If

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Massachusetts
    Posts
    48

    Search Array List Resp

    Thanks for the response---however the code worked only when I supplied all parts of the structure (Item, SoundDiv, SyllDiv)--is there a way to search an array list when only a part of the structure is provided?

    In my program the student sees a sentence, clicks on a word they do not know --the selected texts can be found in the array list divided into sounds and into syllables--and I want the entire structure returned

    Any help?

    Thanks
    Last edited by rcam; Jun 11th, 2003 at 04:00 PM.

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Massachusetts
    Posts
    48
    I think I solved my own problem with the function below---but will it be too slow and is there a faster/easier solution

    Function FindTheSeekWord(ByVal stWord As String) As String
    Dim i As Integer
    Dim stCompare As String

    For i = 0 To ReadWord.Count - 1
    stCompare = ReadWord(i).Item.ToString
    If stCompare = stWord Then
    MessageBox.Show("Got it")
    Return ReadWord(i).Item.ToString & "QQQ" & ReadWord(i).Sounds.ToString & "QQQ" & ReadWord(i).Syll.ToString & "QQQ"
    Exit Function
    End If
    Next

    Return MessageBox.Show("No Match")
    End Function

    I'll use the split function at the "QQQ" on the form

    If you have a faster way --please inform
    Thanks
    Rick

  5. #5
    Lively Member Tygur's Avatar
    Join Date
    Jul 2002
    Posts
    108
    Do you have to use an ArrayList? If you use a SortedList or Hashtable, you can use the word as the key when adding items. This makes it much easier and faster when retrieving items by word.

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Massachusetts
    Posts
    48
    The hashtable seek with the word as the key works great seeking for an item ---now the dumb question---how do I get the object out of the Hash Table

    Dim element As Object

    If HelpTable.ContainsKey(stWord) Then
    element = HelpTable.Item(stWord)
    ProcessTheLetter(element(0).ToString ?????)
    ProcessTheSyllables(element(1).ToString ????)
    Exit Sub
    End If
    I want a retrieve a string so I can process it in a function

    Please help
    Rick

  7. #7
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    .ToString is a .net function that won't work in VB6 or under. I'm not sure which language you are suing to do this.

    If yer using VB it would be

    ProcessTheLetter(element(0))
    ProcessTheSyllables(element(1))

    assuming those are functions and return a value you would say

    TheLetter = ProcessTheLetter(element(0))
    TheSyllable = ProcessTheSyllables(element(1))

    Ofcourse i could be way off base since i'm not sure i follow exactly what you are doing here.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  8. #8
    Lively Member Tygur's Avatar
    Join Date
    Jul 2002
    Posts
    108
    Originally posted by rcam
    The hashtable seek with the word as the key works great seeking for an item ---now the dumb question---how do I get the object out of the Hash Table

    Dim element As Object

    If HelpTable.ContainsKey(stWord) Then
    element = HelpTable.Item(stWord)
    ProcessTheLetter(element(0).ToString ?????)
    ProcessTheSyllables(element(1).ToString ????)
    Exit Sub
    End If
    I want a retrieve a string so I can process it in a function

    Please help
    Rick
    Why are you trying to use element(0) and element(1)? Is element supposed to be an array or something like that? If not, then try just using element without the "(0)" or "(1)".

    Assuming that HelpTable is a Hashtable, element is getting set to the item in the Hashtable whose key matches stWord.

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Massachusetts
    Posts
    48

    Search Array List solved

    Thanks all for the help. I figured it out by referencing the structure within the element object.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width