Results 1 to 5 of 5

Thread: Help with some code [SOLVED]

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    2

    Lightbulb 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

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    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.

  3. #3
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,390

    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

  4. #4
    New Member
    Join Date
    Aug 12
    Posts
    2

    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

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    Re: Help with some code

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    2.         Using ofd As New OpenFileDialog()
    3.             If ofd.ShowDialog() = DialogResult.OK Then
    4.                 MessageBox.Show("Selected " + ofd.FileName)
    5.                 Dim FILE_NAME As String = ofd.FileName
    6.                 Me.TextBox1.Text = My.Computer.FileSystem.ReadAllText("C:\Users\Hudson\Documents\4LetterWords.txt") 'this is multiline? Should be!
    7.                 Dim objReader As New System.IO.StreamReader(FILE_NAME)
    8.                 Dim TextLine As String
    9.                 Do While objReader.Peek() <> -1
    10.  
    11.                     TextLine = objReader.ReadLine() '& vbNewLine  .... try without, it's the string you're interested in
    12.                     If TextBox1.Text.Contains(TextLine) Then
    13.                         RichTextBox1.AppendText(TextLine & vbCrLf) 'not +! Also this would have given you double newline!
    14.                     End If
    15.                 Loop
    16.             Else
    17.                 MsgBox("file does not exist")
    18.             End If
    19.         End Using
    20.     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
  •