-
Dec 8th, 2006, 11:08 PM
#1
Thread Starter
Addicted Member
[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.
-
Dec 9th, 2006, 12:04 AM
#2
Re: [2005] Cycle Through Textfile
Hope a list with 213,557 words would do for the time being
VB Code:
Dim Words() As String
Dim WordNumber As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myReader As New System.IO.StreamReader("c:\WordList.txt", Encoding.Default)
Words = Split(myReader.ReadToEnd, vbCrLf)
myReader.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = "It is a " & Words(WordNumber) & " day!"
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
WordNumber += 1
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.
-
Dec 9th, 2006, 12:07 AM
#3
Addicted Member
Re: [2005] Cycle Through Textfile
well to load the words I would make a function.. somewhat like this
VB Code:
Dim Words As ArrayList = New ArrayList
Function GetWordList() As Integer
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("Words.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
Words.Add(line)
Console.WriteLine(line & " added to word collection")
Loop Until line Is Nothing
sr.Close()
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("Error bye :O check the words.txt man")
Console.ReadKey()
End
End Try
Return Words.Count
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..
-
Dec 9th, 2006, 02:20 AM
#4
Re: [2005] Cycle Through Textfile
VB Code:
Private wordIndex As Integer = 0
Private words As String()
Private Sub LoadWords()
Me.words = IO.File.ReadAllLines("file path here")
End Sub
Private Sub Timer1_Tick(...) Handles Timer1.Tick
Console.WriteLine(Me.words(Me.wordIndex))
Me.wordIndex += 1
If Me.wordIndex = Me.words.Length Then
Me.Timer1.Stop()
End If
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.
-
Dec 9th, 2006, 10:46 AM
#5
Thread Starter
Addicted Member
Re: [2005] Cycle Through Textfile
Thanks for all of the help everyone, I understand most of it
-
Sep 17th, 2010, 01:44 PM
#6
Lively Member
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
-
Sep 18th, 2010, 11:03 AM
#7
Re: [RESOLVED] [2005] Cycle Through Textfile
And what is your question exactly?
-
Sep 19th, 2010, 12:47 AM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|