'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
Friday, November 8, 2013
Read Data from a Text File saved in Resources
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Randomize()
' get the data from text file
' This program reads 5 data Items
' inFile opens the notepad file
inFile = IO.File.OpenText("My.Resources.Resource1.words_txt")
'this function loops around until there is no more data
Do Until inFile.Peek = -1
X = X + 1
'Word(1) stores the first word; Word(2) stores the second word and so forth
Word(X) = inFile.ReadLine
Loop
'you must close the file
inFile.Close()
End Sub
Private Sub btnWord_Click(sender As Object, e As EventArgs) Handles btnWord.Click
y = Int(Rnd() * 10) + 1
lblWord.Text = Word(y)
End Sub
Randomize()
' get the data from text file
' This program reads 5 data Items
' inFile opens the notepad file
inFile = IO.File.OpenText("My.Resources.Resource1.words_txt")
'this function loops around until there is no more data
Do Until inFile.Peek = -1
X = X + 1
'Word(1) stores the first word; Word(2) stores the second word and so forth
Word(X) = inFile.ReadLine
Loop
'you must close the file
inFile.Close()
End Sub
Private Sub btnWord_Click(sender As Object, e As EventArgs) Handles btnWord.Click
y = Int(Rnd() * 10) + 1
lblWord.Text = Word(y)
End Sub
Monday, November 4, 2013
Set the starting position of picCar1 or other object using the location command
Private Sub btnNEW_Click(sender As Object, e As EventArgs) Handles btnNEW.Click
picCar1.Location = New Point(picCar1.Location.X.Equals(0), picCar1.Location.Y.Equals(0))
picCar1.Top = picCar1.Top + 50
picCar1.Left = picCar1.Left + 60 btnNEW.Enabled = False
btnNEW.Visible = False
picCar1.Image = My.Resources.car1_Right
End Sub
picCar1.Location = New Point(picCar1.Location.X.Equals(0), picCar1.Location.Y.Equals(0))
picCar1.Top = picCar1.Top + 50
picCar1.Left = picCar1.Left + 60 btnNEW.Enabled = False
btnNEW.Visible = False
picCar1.Image = My.Resources.car1_Right
End Sub
Subscribe to:
Posts (Atom)