2 Replies - 1537 Views - Last Post: 19 April 2011 - 02:40 PM Rate Topic: -----

#1 hifistyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-October 10

How to pull a random word from a text file and check against user inpu

Posted 19 April 2011 - 02:27 PM

I need to pull a random word from a text file in my resource folder (visual Studio 2010) and then have a user enter a letter to see if it is in the word. Yes, Hangman game. There is more, but right now I need to pull from that text file for a start. I know what I have is not even close to right under "Get Word Button", but I'm kind of confused about the process.
Thanks in advance for any insight.

Public Class hangMan

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim word As New Random

    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles    ExitToolStripMenuItem.Click
        Me.Close()

    End Sub

    Private Sub enterTxtBtn_TextChanged(sender As System.Object, e As System.EventArgs) Handles enterTxtBtn.TextChanged

    End Sub

    Private Sub getWordBtn_Click(sender As System.Object, e As System.EventArgs) Handles getWordBtn.Click
        Dim lines As String()

        If My.Computer.FileSystem.FileExists("Words.txt") Then

            My.Computer.FileSystem.ReadAllText("Words.txt")
            (Text as new Random)
        End If


    End Sub
      


    Private Sub NewGameToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NewGameToolStripMenuItem.Click
       
    End Sub

    Private Sub OvalShape1_Click(sender As System.Object, e As System.EventArgs) Handles OvalShape1.Click

    End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: How to pull a random word from a text file and check against user inpu

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,577
  • Joined: 12-June 08

Re: How to pull a random word from a text file and check against user inpu

Posted 19 April 2011 - 02:33 PM

You are off sort of to a right start.
Verify the file is there. Check.
Read the file. Hmm.. StreamReader is a pretty handy library. Read it all as a string!
Then using that input string you can "split" it by say a space or how ever you are determining one word from another.
Now you have an ARRAY of strings!
Using the math library's random pick a value between zero and the max (minus 1).
Access that random index in the array! Bam!
Was This Post Helpful? 1
  • +
  • -

#3 hifistyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 11-October 10

Re: How to pull a random word from a text file and check against user inpu

Posted 19 April 2011 - 02:40 PM

View Postmodi123_1, on 19 April 2011 - 02:33 PM, said:

You are off sort of to a right start.
Verify the file is there. Check.
Read the file. Hmm.. StreamReader is a pretty handy library. Read it all as a string!
Then using that input string you can "split" it by say a space or how ever you are determining one word from another.
Now you have an ARRAY of strings!
Using the math library's random pick a value between zero and the max (minus 1).
Access that random index in the array! Bam!


Thanks,
I shall try those suggestions!
~J
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1