Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Cycle Through Textfile

  1. #1

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    Resolved [RESOLVED] [2005] Cycle Through Textfile

    Hello, I have found a list of words (http://www.langmaker.com/wordlist/basiclex.htm) that I saved as a txt. I want to be able to cycle through it with my program I am making.

    I have a string and I want it to change everytime that timer3 is finished, timer1 will use it again.

    An example:

    dim theWord as String

    timer1.tick....
    textbox1.text = "It is a " & theWord " day!"
    end sub

    timer2.tick....
    Whatever I have this do
    end sub

    timer3.tick...
    theWord = the next word in the list
    end sub
    How would I accomplish this? Plus if anyone has a better list of words than 850 in txt format, please share.

    Thanks
    Last edited by GedOfEarthsea; Dec 8th, 2006 at 11:55 PM.

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2005] Cycle Through Textfile

    Hope a list with 213,557 words would do for the time being
    VB Code:
    1. Dim Words() As String
    2.     Dim WordNumber As Integer = 0
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Dim myReader As New System.IO.StreamReader("c:\WordList.txt", Encoding.Default)
    6.         Words = Split(myReader.ReadToEnd, vbCrLf)
    7.  
    8.         myReader.Close()
    9.     End Sub
    10.  
    11.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    12.         TextBox1.Text = "It is a " & Words(WordNumber) & " day!"
    13.     End Sub
    14.  
    15.     Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    16.         WordNumber += 1
    17.     End Sub
    What it does is to read the whole list and put each word in the array. Then a word is called by its array index. When you restart the program it will start from the beginning. The list is pretty large and loads slowly. You should choose only as many words as you'll ever need in the app's lifecycle.
    VB 2005, Win Xp Pro sp2

  3. #3
    Addicted Member
    Join Date
    Nov 2006
    Posts
    129

    Re: [2005] Cycle Through Textfile

    well to load the words I would make a function.. somewhat like this
    VB Code:
    1. Dim Words As ArrayList = New ArrayList
    2.  
    3.     Function GetWordList() As Integer
    4.         Try
    5.             ' Create an instance of StreamReader to read from a file.
    6.             Dim sr As StreamReader = New StreamReader("Words.txt")
    7.             Dim line As String
    8.  
    9.             ' Read and display the lines from the file until the end
    10.             ' of the file is reached.
    11.             Do
    12.                 line = sr.ReadLine()
    13.                 Words.Add(line)
    14.                 Console.WriteLine(line & " added to word collection")
    15.             Loop Until line Is Nothing
    16.             sr.Close()
    17.         Catch E As Exception
    18.             ' Let the user know what went wrong.
    19.             Console.WriteLine("Error bye :O check the words.txt man")
    20.             Console.ReadKey()
    21.             End
    22.         End Try
    23.         Return Words.Count
    24.     End Function

    so If you call

    GetWordList it automaticlly populates your Words arraylist and returns the number of words in the list as a number..

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [2005] Cycle Through Textfile

    VB Code:
    1. Private wordIndex As Integer = 0
    2. Private words As String()
    3.  
    4. Private Sub LoadWords()
    5.     Me.words = IO.File.ReadAllLines("file path here")
    6. End Sub
    7.  
    8. Private Sub Timer1_Tick(...) Handles Timer1.Tick
    9.     Console.WriteLine(Me.words(Me.wordIndex))
    10.     Me.wordIndex += 1
    11.  
    12.     If Me.wordIndex = Me.words.Length Then
    13.         Me.Timer1.Stop()
    14.     End If
    15. End Sub
    This is not a full solution but you get the idea. The main thing I wanted to show is how easy it is to read the words.

  5. #5

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    Re: [2005] Cycle Through Textfile

    Thanks for all of the help everyone, I understand most of it

  6. #6
    Lively Member Amerigo's Avatar
    Join Date
    Dec 2008
    Location
    PSR B1620-26 c-1
    Posts
    126

    Re: [RESOLVED] [2005] Cycle Through Textfile

    I'm needing to do something similar, but without displaying the words. It more complex (I think) because I need to compare each word in Textbox1 to see if it is found in a dictionary file. Spell check? nope.
    If the word is not in the dictionary file, a popup will appear asking if it is a name. If it's not a name, then it can be added to the dictionary file (if it is an actual word and spelled correctly).
    If it is a name, then a character profile will be created and assigned a voice.

    It will get even more complex at read/record time... it will need to determine if a dialog exist "....", who said it, and in what manner of speech (said, asked, sobbed, screamed, whined, etc...).
    Anyone who does not wonder, is either omnipotent or a fool.
    Amerigoware <<<My Projects

  7. #7
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [RESOLVED] [2005] Cycle Through Textfile

    And what is your question exactly?
    VB 2005, Win Xp Pro sp2

  8. #8
    Addicted Member
    Join Date
    Nov 2006
    Posts
    129

    Re: [RESOLVED] [2005] Cycle Through Textfile

    store textbox result into a variable.

    Btw in my old example the words are loaded into a ArrayList you don't really see them.

    You can then use Like


    Code:
     If Not Words.Contains("Your Word") Then
                alPersons.Add(1, "Your Word")
     End If

    Haven't coded in VB.NET for years can't really say any .NET language is useful

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