Help with flash card program
Hi. I'm totally new to programming. Anyway, I'm a teacher and am writing a program that simply shows kids a word on a flashcard. There are 2 buttons, 1 to read the word and 1 to go to a new work. There are going to be 300 words.
Really I'm just testing it right here. What I want to know is should I be inputting all the words right into the code like I did with "hi" and "not 1" (Don't ask. those are just the 2 random words I picked to test this out with).
OR is there a better way (maybe somehow to type all the words on a text file and have the program randomly pull one of them (I don't know how to do this).
Here is the code so far:
Public Class Form1
Dim word
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim random As New Random
Dim num As Integer
num = random.Next(1, 3)
If num = 1 Then Label1.Text = ("hi")
If num <> 1 Then Label1.Text = ("not 1")
word = num
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If word = 1 Then My.Computer.Audio.Play(My.Resources.hi, AudioPlayMode.Background)
If word <> 1 Then My.Computer.Audio.Play(My.Resources.not_hi, AudioPlayMode.Background)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Re: Help with flash card program
Reading words from a file is really easy. Put all of your words in a file, each word on a different line. Then you can use code like this to load the words and select a new word each time the button is pushed:
Code:
' An array to store the words
Dim Words() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Read all of the words from a file
Words = IO.File.ReadAllLines("C:\Temp\wordsfile.txt")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a random number, so we get a random word each time.
Dim r As New Random
Dim index As Integer = r.Next(0, Words.Length)
' Put the random word into the label.
Label1.Text = Words(index)
End Sub
Re: Help with flash card program
Quote:
Originally Posted by Negative0
Reading words from a file is really easy. Put all of your words in a file, each word on a different line. Then you can use code like this to load the words and select a new word each time the button is pushed:
Code:
' An array to store the words
Dim Words() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Read all of the words from a file
Words = IO.File.ReadAllLines("C:\Temp\wordsfile.txt")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a random number, so we get a random word each time.
Dim r As New Random
Dim index As Integer = r.Next(0, Words.Length)
' Put the random word into the label.
Label1.Text = Words(index)
End Sub
What if I want everything to be in one .exe? Is there a way to put the word list in as a resource?
Again. so sorry for the noob questions. Saturday was the first time I've seen VB and haven't coded since my C class in college like 13 years ago.