5 Replies - 1457 Views - Last Post: 22 April 2011 - 10:48 AM Rate Topic: -----

#1 hifistyle  Icon User is offline

  • New D.I.C Head

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

Pull random word from file in visual Studio and match against user

Posted 20 April 2011 - 01:03 PM

I have to use the word list supplied and cannot use "streamreader" so, I need to pull a random word from text file in my resource folder (Visual Studio 2010) so user can guess letters for hangman game). I don't know if the code under "get word" button is right or not as far as pulling from the file. I would like to get that far!

Imports System.IO

Public Class hangMan

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

    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 enterTxtBox.TextChanged

    End Sub

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

        Lines = My.Resources.Words.Split(Chr(13))
        MyLines = lines.ToList

        
    End Sub


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

    End Sub


    Private Sub checkBtn_Click(sender As System.Object, e As System.EventArgs) Handles checkBtn.Click

    End Sub

   
    
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Pull random word from file in visual Studio and match against user

#2 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2506
  • View blog
  • Posts: 4,615
  • Joined: 24-September 10

Re: Pull random word from file in visual Studio and match against user

Posted 20 April 2011 - 02:13 PM

You hardly do anything in that method.

You create a Random object, ok, good start, we're going to need this.

Then you declare a string called lines...

Then you split some Resource (I'm guessing a txt doc with all your words delimited by the line they're on). It's set to a var called 'Lines', which maybe should have been 'lines' (case sensitive). But 'lines' is a String, not a String array... so we're asking for an error here.

Then you ToList 'lines'? Well... If 'lines' is an array this method doesn't exist. And if it's a String, then this returns a List of all the Chars in the string (not all the words).



And that's it... you don't even bother to try and select anything.
Was This Post Helpful? 0
  • +
  • -

#3 hifistyle  Icon User is offline

  • New D.I.C Head

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

Re: Pull random word from file in visual Studio and match against user

Posted 20 April 2011 - 02:50 PM

Yup, that's about the size of it.

This post has been edited by hifistyle: 20 April 2011 - 03:02 PM

Was This Post Helpful? -1
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: Pull random word from file in visual Studio and match against user

Posted 20 April 2011 - 05:04 PM

View Posthifistyle, on 20 April 2011 - 02:50 PM, said:

Yup, that's about the size of it.


I think you might want to look into String Manipulation. I really think you should look up the Streamreader, and Streamwriter methods of the System.Io Namespace. They are great for practice, and will more than solidify your concept of all these goodies. :)

This post has been edited by trevster344: 20 April 2011 - 05:06 PM

Was This Post Helpful? 0
  • +
  • -

#5 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2506
  • View blog
  • Posts: 4,615
  • Joined: 24-September 10

Re: Pull random word from file in visual Studio and match against user

Posted 22 April 2011 - 10:13 AM

hifistyle said:

...I don't know if the code under "get word" button is right or not as far as pulling from the file. I would like to get that far!


Was there something I was missing? Did I not respond to your statement? Oh you were hoping for an answer to something. To what might I ask? You didn't ask any question in your entire post. Instead like a rude new member of the community you just posted your code, pretended that you put effort in by commenting on jibberish you wrote in some random method, and then expect us to give you what else is needed.

... good luck with that one.



@travester, he doesn't need anything from System.IO, he's using the My.Resources namespace and the Resources part of the project which handles the file for him. He can access the value like a String from My.Resources.NameOfResource.

He obviously doesn't know how to parse a string into the data he needs. He aught to be looking at the String class and maybe asking more direct questions and maybe doing some research on what a String, Char, and Array are (some of the most basic structures in programming).

This post has been edited by lordofduct: 22 April 2011 - 10:16 AM

Was This Post Helpful? 0
  • +
  • -

#6 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: Pull random word from file in visual Studio and match against user

Posted 22 April 2011 - 10:48 AM

View Postlordofduct, on 22 April 2011 - 10:13 AM, said:

hifistyle said:

...I don't know if the code under "get word" button is right or not as far as pulling from the file. I would like to get that far!


Was there something I was missing? Did I not respond to your statement? Oh you were hoping for an answer to something. To what might I ask? You didn't ask any question in your entire post. Instead like a rude new member of the community you just posted your code, pretended that you put effort in by commenting on jibberish you wrote in some random method, and then expect us to give you what else is needed.

... good luck with that one.



@travester, he doesn't need anything from System.IO, he's using the My.Resources namespace and the Resources part of the project which handles the file for him. He can access the value like a String from My.Resources.NameOfResource.

He obviously doesn't know how to parse a string into the data he needs. He aught to be looking at the String class and maybe asking more direct questions and maybe doing some research on what a String, Char, and Array are (some of the most basic structures in programming).


I agree with you, some practice elsewhere is needed before attempting this project.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1