|
-
Aug 20th, 2012, 09:03 PM
#1
Thread Starter
New Member
Help with some code [SOLVED]
I am trying to create a program that goes through a text file full of four character lines. It should take each line and send it through www.isthisaword.com. it should then check to see if the website thinks the four letters make up a word. If they do make up a word then it should put the word in a text box and continue to check the other lines. the end result should be a textbox filled with a list of four letter words taken from the text file. As of right now the program only tries to see if the very last four letter string in the text file is a word, and even if it is a word, it does not write it to the textbox. could anyone help me please? P.S. this is pretty much the first program i have ever created, so sorry its not the neatest code.
Example of the text file (over 10,000 of these four letter strings):
tcmv
uwnr
ysun
dnci
csrg
fohj
rtyv
ybmx
xywd
cism
ihju
wkro
huvg
ynts
bwdq
gjvf
mbgd
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using ofd As New OpenFileDialog()
If ofd.ShowDialog() = DialogResult.OK Then
MessageBox.Show("Selected " + ofd.FileName)
Dim FILE_NAME As String = ofd.FileName
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim TextLine As String
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine() & vbNewLine
WebBrowser1.Navigate("www.isthisaword.com/" + TextLine)
Dim Inner As String = WebBrowser1.Document.Body.InnerHtml
If InStr(Inner, "YES") <> 0 Then
RichTextBox1.Text = RichTextBox1.Text + TextLine & vbnewline
End If
Loop
Else
MsgBox("file does not exist")
End If
End Using
End Sub
Last edited by strpwnsulol; Aug 21st, 2012 at 11:42 AM.
Reason: SOLVED
-
Aug 21st, 2012, 09:45 AM
#2
Re: Help with some code
The problem is that you don't give the website any time to respond before moving on to the next instruction and then the next line of the file. Having said that, if you did, my guess is it would take a very, very long time (well over 2 hours) to complete 10000 checks. There are plenty of free word lists in text form available on the internet. You would be much better off downloading one and using that for your comparisons.
-
Aug 21st, 2012, 10:14 AM
#3
Re: Help with some code
I agree. 10,000 web calls will kill your performance. What you would have to do would be to change the code around so that you navigate to the site for the first word, then in the DocumentCompleted event you would process the response for that word and navigate to the next word. If you have one second response time for the site (which is fast, but possible), then you would be looking at 10,000 seconds, or nearly 3 hours to check the whole list.
My usual boring signature: Nothing
 
-
Aug 21st, 2012, 11:09 AM
#4
Thread Starter
New Member
Re: Help with some code
Thanks guys i went with dunfiddlin's advice and got a .txt of 4 letter words (http://www.scrabble.org.au/words/fours.htm) However i am still running into a problem with the RichTextBox, it will not record the words that it should be recording. To test this out i put "coat" at the start of the file i want to check, "coat" is also in the "4LetterWords.txt" I let the program run for a while but no words are recorded, i thought this might be a issue with the lowercase being compared to the uppercase so i changed everything to lowercase. still no recorded words 
Im pretty sure i am doing the write to textbox correctly but maybe not, here is my new code, i made an invisible textbox where the dictionary list is written. Then the program checks if the file contains the TextLine. Also im not sure if im doing the TextLine right. It might not be only using one line.
SOLVED!
The & vbNewLine was causing it to skip straight to the very last entry and record nothing.
Broken Code:
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using ofd As New OpenFileDialog()
If ofd.ShowDialog() = DialogResult.OK Then
MessageBox.Show("Selected " + ofd.FileName)
Dim FILE_NAME As String = ofd.FileName
Me.TextBox1.Text = My.Computer.FileSystem.ReadAllText("C:\Users\Hudson\Documents\4LetterWords.txt")
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim TextLine As String
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine() & vbNewLine
If TextBox1.Text.Contains(TextLine) Then
RichTextBox1.Text = RichTextBox1.Text + TextLine & vbNewLine
End If
Loop
Else
MsgBox("file does not exist")
End If
End Using
End Sub
Working Code
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using ofd As New OpenFileDialog()
If ofd.ShowDialog() = DialogResult.OK Then
MessageBox.Show("Selected " + ofd.FileName)
Dim FILE_NAME As String = ofd.FileName
Me.TextBox1.Text = My.Computer.FileSystem.ReadAllText("C:\Users\Hudson\Documents\4LetterWords.txt")
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim TextLine As String
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine()
TextBox2.Text = TextLine
If TextBox1.Text.Contains(TextLine) Then
TextBox3.Text &= Environment.NewLine & TextLine
Else
End If
Loop
Else
MsgBox("file does not exist")
End If
End Using
End Sub
Last edited by strpwnsulol; Aug 21st, 2012 at 11:41 AM.
Reason: SOLVED
-
Aug 21st, 2012, 11:26 AM
#5
Re: Help with some code
vb.net Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using ofd As New OpenFileDialog()
If ofd.ShowDialog() = DialogResult.OK Then
MessageBox.Show("Selected " + ofd.FileName)
Dim FILE_NAME As String = ofd.FileName
Me.TextBox1.Text = My.Computer.FileSystem.ReadAllText("C:\Users\Hudson\Documents\4LetterWords.txt") 'this is multiline? Should be!
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim TextLine As String
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine() '& vbNewLine .... try without, it's the string you're interested in
If TextBox1.Text.Contains(TextLine) Then
RichTextBox1.AppendText(TextLine & vbCrLf) 'not +! Also this would have given you double newline!
End If
Loop
Else
MsgBox("file does not exist")
End If
End Using
End Sub
Last edited by dunfiddlin; Aug 21st, 2012 at 11:31 AM.
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
|