e-dictionary_8000 pairs of word and meaning_fast&quick

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

65 Replies - 2555 Views - Last Post: 07 June 2013 - 11:06 PM Rate Topic: -----

#1 joramkaku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 12-April 13

e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 12 April 2013 - 05:24 AM

'I am working on a dictionary project for word meaning search which is written in VB10.net . it contain around 8,000 pairs of word and meaning.

'When i run, it loads perfectly but when i click on the search button or press Enter or double click word in the listbox, it start "Not responding" for around 30 seconds. Then it works. But when tested in my friends PC it never returns from "Not responding" state.


'Any help will be appreciated, TO OVER COME THIS "NOT RESPONDING" PROBLEM. Especially to make it Fast and Quick.
Thanks.
'Dictionary code is as follows:
Attached File  edictionary source code.txt (4.93K)
Number of downloads: 36
Public Class Form1

    Private Sub Form1_Load(byVal sender As System.Object, byVal e As System.EventArgs) Handles MyBase.Load
        

        'a
        ListBox1.Items.Add("a")
        ListBox1.Items.Add("aba")
        ListBox1.Items.Add("abah")
        ListBox1.Items.Add("abey")
        ListBox1.Items.Add("abi")
        ListBox1.Items.Add("abie")
        ListBox1.Items.Add("abii")
        ListBox1.Items.Add("abo")
       




        ListBox1.Sorted = True
    End Sub

    Private Sub AboutUsToolStripMenuItem_Click(byVal sender As System.Object, byVal e As System.EventArgs) Handles AboutUsToolStripMenuItem.Click
        AboutBox1.Show()

    End Sub

    Private Sub EndToolStripMenuItem_Click(byVal sender As System.Object, byVal e As System.EventArgs) Handles EndToolStripMenuItem.Click
        End

    End Sub

    Private Sub TextBox1_TextChanged(byVal sender As System.Object, byVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim Item As String = TextBox1.Text.ToString()
        Dim index As Integer = ListBox1.FindString(Item)
        If index = -1 Then
            ListBox1.SelectedIndex = ListBox1.SelectedIndex
        Else
            ListBox1.SetSelected(index, True)

        End If
        
    End Sub

    Private Sub button1_Click(byVal sender As System.Object, byVal e As System.EventArgs) Handles button1.Click




            If TextBox1.Text ="a"Then
                TextBox2.Text = TextBox1.Text
                TextBox3.Text ="Verb"
                TextBox4.Text ="to come; to enter."
        ElseIf TextBox1.Text ="aba"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text ="Adverb"
            TextBox4.Text ="To come together/at the same time."
        ElseIf TextBox1.Text ="abah"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text ="Adverb"
            TextBox4.Text ="to come in addition to sb."
        ElseIf TextBox1.Text ="abey"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text ="Adverb"
            TextBox4.Text ="bored after coming regularly for a long time."
        ElseIf TextBox1.Text ="abi"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text =""
            TextBox4.Text ="to come on behalf of other."
        ElseIf TextBox1.Text ="abie"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text =""
            TextBox4.Text ="to come with pleasure."
        ElseIf TextBox1.Text ="abii"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text =""
            TextBox4.Text ="to have come."
        ElseIf TextBox1.Text ="abo"Then
            TextBox2.Text = TextBox1.Text
            TextBox3.Text ="Adverb"
            TextBox4.Text ="to come along with sb. Annii ageen ho paze atu si abo mondo.(the duckling is coming with its mother)."
        


        Else
            MsgBox("No Match Found!!")
        End If
    End Sub


    Private Sub ListBox1_DoubleClick(byVal sender As System.Object, byVal e As System.EventArgs)
        TextBox1.Text = ListBox1.SelectedItem
        button1.PerformClick()
    End Sub

    Private Sub TextBox2_TextChanged(byVal sender As System.Object, byVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub MenuStrip1_ItemClicked(byVal sender As System.Object, byVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub Form1_DoubleClick(byVal seNounder As System.Object, byVal e As System.EventArgs) Handles MyBase.DoubleClick

    End Sub

    Private Sub ListBox1_DoubleClick_1(byVal seNounder As System.Object, byVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem
        button1.PerformClick()
    End Sub

    Private Sub SplashScreenToolStripMenuItem_Click(byVal sender As System.Object, byVal e As System.EventArgs) Handles SplashScreenToolStripMenuItem.Click
        SplashScreen1.Show()

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(byVal sender As System.Object, byVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub

    Private Sub CreditsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreditsToolStripMenuItem.Click
        Form2.Show()

    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: e-dictionary_8000 pairs of word and meaning_fast&quick

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 12 April 2013 - 06:30 AM

What you have here works well, without delay, on my machine. Of course, I expected it to because there are only 8 pais of words/meanings, so searches are fast. I am wondering where your 8,000 entry dictionary actually is.

Do you have a file that you are searching? If so, it might be worth looking at that to see if it's properly formed, and post the code that searches it.
Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 778
  • Joined: 01-February 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 12 April 2013 - 07:19 AM

Hello,
I see a few things that should be changed but, they are probably not the cause of your problem. The first is in the ListBox DoubleClick event. The (ListBox1.SelectedItem) is actually an object and should have the (ToString) on the end to return it as a string.
    Private Sub ListBox1_DoubleClick_1(ByVal seNounder As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString
        Button1.PerformClick()
    End Sub



The second thing is in the (TextBox1_TextChanged) event. The (TextBox1.Text) does not need the (ToString) on it because, the (Text) property of the textbox is already a string.
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim Item As String = TextBox1.Text 'No need for the (ToString) the (Text) is already a string
        Dim index As Integer = ListBox1.FindString(Item)
        If index = -1 Then
            ListBox1.SelectedIndex = ListBox1.SelectedIndex
        Else
            ListBox1.SetSelected(index, True)
        End If
    End Sub


You could change the (TextBox1_TextChanged) event to the following just to clean it up. There is no need to set the selectedindex to the selectedindex if the item was not found.
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If
    End Sub


:bigsmile:/>/>

This post has been edited by IronRazer: 12 April 2013 - 07:26 AM

Was This Post Helpful? 0
  • +
  • -

#4 joramkaku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 12-April 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 12 April 2013 - 09:30 PM

View Postlar3ry, on 12 April 2013 - 06:30 AM, said:

What you have here works well, without delay, on my machine. Of course, I expected it to because there are only 8 pais of words/meanings, so searches are fast. I am wondering where your 8,000 entry dictionary actually is.

Do you have a file that you are searching? If so, it might be worth looking at that to see if it's properly formed, and post the code that searches it.


Thank you.

I have attached the around 8000 pairs of word/meaning. please check if there is any thing i will need to make over.

View PostIronRazer, on 12 April 2013 - 07:19 AM, said:

Hello,
I see a few things that should be changed but, they are probably not the cause of your problem. The first is in the ListBox DoubleClick event. The (ListBox1.SelectedItem) is actually an object and should have the (ToString) on the end to return it as a string.
    Private Sub ListBox1_DoubleClick_1(ByVal seNounder As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString
        Button1.PerformClick()
    End Sub



The second thing is in the (TextBox1_TextChanged) event. The (TextBox1.Text) does not need the (ToString) on it because, the (Text) property of the textbox is already a string.
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim Item As String = TextBox1.Text 'No need for the (ToString) the (Text) is already a string
        Dim index As Integer = ListBox1.FindString(Item)
        If index = -1 Then
            ListBox1.SelectedIndex = ListBox1.SelectedIndex
        Else
            ListBox1.SetSelected(index, True)
        End If
    End Sub


You could change the (TextBox1_TextChanged) event to the following just to clean it up. There is no need to set the selectedindex to the selectedindex if the item was not found.
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If
    End Sub


:bigsmile:/>/>/>


Thank you for your time and helping me out. If i encounter any further problem i am sure to get back to you. Thank you again.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#5 joramkaku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 12-April 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 12 April 2013 - 10:59 PM

View PostIronRazer, on 12 April 2013 - 07:19 AM, said:

Hello,
I see a few things that should be changed but, they are probably not the cause of your problem. The first is in the ListBox DoubleClick event. The (ListBox1.SelectedItem) is actually an object and should have the (ToString) on the end to return it as a string.
    Private Sub ListBox1_DoubleClick_1(ByVal seNounder As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString
        Button1.PerformClick()
    End Sub



The second thing is in the (TextBox1_TextChanged) event. The (TextBox1.Text) does not need the (ToString) on it because, the (Text) property of the textbox is already a string.
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim Item As String = TextBox1.Text 'No need for the (ToString) the (Text) is already a string
        Dim index As Integer = ListBox1.FindString(Item)
        If index = -1 Then
            ListBox1.SelectedIndex = ListBox1.SelectedIndex
        Else
            ListBox1.SetSelected(index, True)
        End If
    End Sub


You could change the (TextBox1_TextChanged) event to the following just to clean it up. There is no need to set the selectedindex to the selectedindex if the item was not found.
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If
    End Sub


:bigsmile:/>/>/>


I have re-corrected in my code. But still the problem "Not Responding" persist.
How to overcome it.
I will be thankful for your time and help. Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 778
  • Joined: 01-February 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 08:54 AM

Hello,
You could fix this many different ways. Here is just one way (Maybe not the best way) you could do it. Keep your Word data in a text file and have your program read the file in the FormLoad event and list the words in the listbox and assign the (noun,adj,pronoun,....) to one List(Of String) and assign the Definitions to another List(Of String). Now whatever word is selected in the listbox you can set the proper textbox`s to the data stored in the two lists at the same index as the listbox SelectedIndex. For example if Listbox1 SelectedIndex is (243) then set the textboxes to the data of the lists index (243). Here is a working example of doing it this way
Public Class Form1
    Dim adjlist As New List(Of String) 'list for the noun, verb, or whatever
    Dim deflist As New List(Of String) 'list for the definition

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sr As New System.IO.StreamReader("C:\test\WordData.txt") 'Set to wherever the WordData File is located
        While Not sr.EndOfStream
            ListBox1.Items.Add(sr.ReadLine) 'add word to listbox
            adjlist.Add(sr.ReadLine()) 'add the Noun,Verb, or whatever to the (adjlist)
            deflist.Add(sr.ReadLine()) 'add the definition to the (deflist)
            sr.ReadLine() 'this is to read the (-----) separator line. DO NOT REMOVE!!
        End While
        sr.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If
    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString 'Set textbox1 to the word that was double clicked
        Button1.PerformClick()
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'if the word was typed in textbox1 then we need to check to see if the list of words contains
        'the word and check to see if there is a word selected in the listbox.
        If ListBox1.SelectedIndex > -1 And ListBox1.Items.Contains(TextBox1.Text) Then
            TextBox2.Text = ListBox1.SelectedItem.ToString 'set textbox2 to the selected word
            TextBox3.Text = adjlist(ListBox1.SelectedIndex) 'set textbox3 to the adjlist index of the selected listbox index
            TextBox4.Text = deflist(ListBox1.SelectedIndex) 'set textbox4 to the deflist index of the selected listbox index
        Else
            MessageBox.Show("Word Not Found")
        End If
    End Sub
End Class


Here is the word and definition list for it. You must keep the words in order when entering new words and definitions into the list. Attached File  WordData.txt (785.47K)
Number of downloads: 30 B)
Was This Post Helpful? 1
  • +
  • -

#7 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 10:24 AM

IronRazer's advice is very good, and it will fix your problem quite nicely. In general, code is not a good place to store data. It's fine for fixed strings (error messages, titles of things, etc.), but certainly not for large amounts of data. You've already seen what it can do to speed of lookup, and in addition, you have to modify the code to add words to the dictionary.

I did notice something in your word/definition list, and whenever I see it, I like to point it out to people who use it.

There are many instances of two abbreviations that are never used in standard English writing. They are used only in EFL or ESL courses and textbooks, and if you use them in normal writing, they will not be understood by the majority of native English speakers.

The abbreviations I refer to are sb and sth, and you should always, when writing English, use somebody or something

Here's the file IronRazer sent you, with the abbreviations replaced.

Attached File(s)


Was This Post Helpful? 1
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3331
  • View blog
  • Posts: 11,270
  • Joined: 12-December 12

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 10:49 AM

All those dashes
--------------------------------------------
take up a third of the size of the file. Personally, I would globally replace them with
-----
that is, enough to remain as a visual separator. Although, I appreciate that this is just a minor point, and you may prefer to keep them.

This post has been edited by andrewsw: 13 April 2013 - 10:50 AM

Was This Post Helpful? 0
  • +
  • -

#9 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 778
  • Joined: 01-February 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 11:09 AM

View Postandrewsw, on 13 April 2013 - 12:49 PM, said:

All those dashes
--------------------------------------------
take up a third of the size of the file. Personally, I would globally replace them with
-----
that is, enough to remain as a visual separator. Although, I appreciate that this is just a minor point, and you may prefer to keep them.

That would be a good idea. It would help keep the file size down a little. I was not thinking about that when adding them. I only put them in to make it easier to tell where each words data starts and ends. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3331
  • View blog
  • Posts: 11,270
  • Joined: 12-December 12

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 11:15 AM

View PostIronRazer, on 13 April 2013 - 06:09 PM, said:

View Postandrewsw, on 13 April 2013 - 12:49 PM, said:

All those dashes
--------------------------------------------
take up a third of the size of the file. Personally, I would globally replace them with
-----
that is, enough to remain as a visual separator. Although, I appreciate that this is just a minor point, and you may prefer to keep them.

That would be a good idea. It would help keep the file size down a little. I was not thinking about that when adding them. I only put them in to make it easier to tell where each words data starts and ends. :bigsmile:/>

I would make them all specifically 5 characters (-----). This way I know that I could replace them all in one go :)

But maybe I have OCD :whatsthat:

This post has been edited by andrewsw: 13 April 2013 - 11:17 AM

Was This Post Helpful? 0
  • +
  • -

#11 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 236
  • View blog
  • Posts: 778
  • Joined: 01-February 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 11:28 AM

True. I made them all the same size in mine so, all the OP would have to do is open the file in notepad and use Replace to replace all the (-------------------) with (-----). B)
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3331
  • View blog
  • Posts: 11,270
  • Joined: 12-December 12

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 12:13 PM

View PostIronRazer, on 13 April 2013 - 06:28 PM, said:

True. I made them all the same size in mine so, all the OP would have to do is open the file in notepad and use Replace to replace all the (-------------------) with (-----). B)

He, he! I thought some of them were different lengths, but it proved to be an optical illusion :online2long:
Was This Post Helpful? 0
  • +
  • -

#13 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 13 April 2013 - 11:46 PM

Well, I've modified both the WordData file and IronRazer's code.

The file now consists of entries containing all three fields, and each entry is on one line, delimited with a "~" character. This, I feel makes it a little easier to add entries, and to keep things together and in sync.

Here's the code:

Option Strict On

Public Class Form1
    Dim adjlist As New List(Of String) 'list for the noun, verb, or whatever
    Dim deflist As New List(Of String) 'list for the definition

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sr As New System.IO.StreamReader("WordDataX.txt") 'Set to wherever the WordData File is located
        Dim inline(2) As String
        Dim temp As String
        While Not sr.EndOfStream
            temp = sr.ReadLine
            inline = temp.Split(CChar("|"))
            ListBox1.Items.Add(inline(0)) 'add word to listbox
            'Application.DoEvents()
            adjlist.Add(inline(1)) 'add the Noun,Verb, or whatever to the (adjlist)
            deflist.Add(inline(2)) 'add the definition to the (deflist)
            'sr.ReadLine() 'this is to read the (-----) separator line. DO NOT REMOVE!!
        End While
        sr.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If
    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString 'Set textbox1 to the word that was double clicked
        Button1.PerformClick()
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'if the word was typed in textbox1 then we need to check to see if the list of words contains
        'the word and check to see if there is a word selected in the listbox.
        If ListBox1.SelectedIndex > -1 And ListBox1.Items.Contains(TextBox1.Text) Then
            TextBox2.Text = ListBox1.SelectedItem.ToString 'set textbox2 to the selected word
            TextBox3.Text = adjlist(ListBox1.SelectedIndex) 'set textbox3 to the adjlist index of the selected listbox index
            TextBox4.Text = deflist(ListBox1.SelectedIndex) 'set textbox4 to the deflist index of the selected listbox index
        Else
            MessageBox.Show("Word Not Found")
        End If
    End Sub
End Class



And here's the WordData file, renamed to WordDataX.txt to prevent download overwrites:

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#14 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • Joined: 29-May 08

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 14 April 2013 - 03:34 AM

Have you thought about a different data structure?
Directed Acyclic Word Graph (aka DAWG)

Along with a Custom class to encapsulate the Word Definition?

Serialise it to a file.

On load deserialize it.

This post has been edited by AdamSpeight2008: 14 April 2013 - 03:35 AM

Was This Post Helpful? 0
  • +
  • -

#15 joramkaku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 12-April 13

Re: e-dictionary_8000 pairs of word and meaning_fast&quick

Posted 14 April 2013 - 04:11 AM

View Postlar3ry, on 13 April 2013 - 11:46 PM, said:

Well, I've modified both the WordData file and IronRazer's code.

The file now consists of entries containing all three fields, and each entry is on one line, delimited with a "~" character. This, I feel makes it a little easier to add entries, and to keep things together and in sync.

Here's the code:

Option Strict On

Public Class Form1
    Dim adjlist As New List(Of String) 'list for the noun, verb, or whatever
    Dim deflist As New List(Of String) 'list for the definition

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sr As New System.IO.StreamReader("WordDataX.txt") 'Set to wherever the WordData File is located
        Dim inline(2) As String
        Dim temp As String
        While Not sr.EndOfStream
            temp = sr.ReadLine
            inline = temp.Split(CChar("|"))
            ListBox1.Items.Add(inline(0)) 'add word to listbox
            'Application.DoEvents()
            adjlist.Add(inline(1)) 'add the Noun,Verb, or whatever to the (adjlist)
            deflist.Add(inline(2)) 'add the definition to the (deflist)
            'sr.ReadLine() 'this is to read the (-----) separator line. DO NOT REMOVE!!
        End While
        sr.Close()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If
    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString 'Set textbox1 to the word that was double clicked
        Button1.PerformClick()
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'if the word was typed in textbox1 then we need to check to see if the list of words contains
        'the word and check to see if there is a word selected in the listbox.
        If ListBox1.SelectedIndex > -1 And ListBox1.Items.Contains(TextBox1.Text) Then
            TextBox2.Text = ListBox1.SelectedItem.ToString 'set textbox2 to the selected word
            TextBox3.Text = adjlist(ListBox1.SelectedIndex) 'set textbox3 to the adjlist index of the selected listbox index
            TextBox4.Text = deflist(ListBox1.SelectedIndex) 'set textbox4 to the deflist index of the selected listbox index
        Else
            MessageBox.Show("Word Not Found")
        End If
    End Sub
End Class



And here's the WordData file, renamed to WordDataX.txt to prevent download overwrites:


I have done the coding exactly as you suggested and used the WordDataX.txt and saved it in C:\test\WordDataX.txt.
When i run the application, listbox1 doesn't load a single word.

Option Strict On

Imports System.IO
Imports System.Collections.Generic
Imports System.Windows.Forms

Public Class Form1
    Dim adjlist As New List(Of String) 'list for the noun, verb, or whatever
    Dim deflist As New List(Of String) 'list for the definition

    Private Sub Form1_GiveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles Me.GiveFeedback
        Dim sr As New System.IO.StreamReader("C:\test\WordDataX.txt") 'Set to wherever the WordData File is located
        Dim inline(2) As String
        Dim temp As String
        While Not sr.EndOfStream
            temp = sr.ReadLine
            inline = temp.Split(CChar("|"))
            ListBox1.Items.Add(sr.ReadLine) 'add word to listbox
            'Application.doEvents()
            adjlist.Add(sr.ReadLine()) 'add the Noun,Verb, or whatever to the (adjlist)
            deflist.Add(sr.ReadLine()) 'add the definition to the (deflist)
            'sr.ReadLine() 'this is to read the (-----) separator line. DO NOT REMOVE!!
        End While
        sr.Close()

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim index As Integer = ListBox1.FindString(TextBox1.Text)
        If index > -1 Then
            ListBox1.SelectedIndex = index
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'if the word was typed in textbox1 then we need to check to see if the list of words contains
        'the word and check to see if there is a word selected in the listbox.
        If ListBox1.SelectedIndex > -1 And ListBox1.Items.Contains(TextBox1.Text) Then
            TextBox2.Text = ListBox1.SelectedItem.ToString 'set textbox2 to the selected word
            TextBox3.Text = adjlist(ListBox1.SelectedIndex) 'set textbox3 to the adjlist index of the selected listbox index
            TextBox4.Text = deflist(ListBox1.SelectedIndex) 'set textbox4 to the deflist index of the selected listbox index
        Else
            MessageBox.Show("Word Not Found")
        End If

    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        TextBox1.Text = ListBox1.SelectedItem.ToString 'set textbox1 to the word that ws double clicked.
        Button1.PerformClick()
    End Sub
End Class


Please help.
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »