|
-
Jun 10th, 2003, 08:15 PM
#1
Thread Starter
Member
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??
-
Jun 10th, 2003, 10:53 PM
#2
Frenzied Member
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:
If (ReadWord.Contains("Word")) Then
MessageBox.Show("Word found")
End If
-
Jun 11th, 2003, 12:35 PM
#3
Thread Starter
Member
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.
-
Jun 11th, 2003, 03:57 PM
#4
Thread Starter
Member
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
-
Jun 12th, 2003, 01:56 AM
#5
Lively Member
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.
-
Jun 13th, 2003, 02:13 PM
#6
Thread Starter
Member
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
-
Jun 13th, 2003, 05:19 PM
#7
PowerPoster
.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.

-
Jun 13th, 2003, 05:52 PM
#8
Lively Member
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.
-
Jun 14th, 2003, 07:36 AM
#9
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|