Friday, November 8, 2013

Reading Data from a Resourse Text File

 'FIRST- Make a text file using Notepad and save it in the same
 'folder as your Project

    'MAKE SURE that you don't hit Enter after the Last Data Item
    'in your Notepad file. Name it something like myData.txt 

  'Second:  you MUST setup the resource file- To Do this:      'Choose the Project Tab- Name-Of-the-Project's Properties
          (absolute bottom choice)
      'Choose the Resources Tab on the Left
      'Choose Add Resources
      'It should place the Resource ICON in the Window
      'Now you can use the code below to read the data
          'from the resource text file

Public Class Form1
    'With the following code, words are stored Word(0) to Word(9)
    Dim Word() As String = Split(My.Resources.mywords, vbLf)
    'y generates the Random Number
    Dim y As Integer

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

    End Sub
End Class
    Private Sub btnWord_Click(sender As Object, e As EventArgs) Handles btnWord.Click
      'y gets a number between 0 and 9
        y = Int(Rnd() * 10)
        lblWord.Text = Word(y)
    End Sub

No comments:

Post a Comment