I have been given a task to:
Develop a program where a child will be presented with picture of a fruit (one of five possible fruit) on the screen at the click of a start button. The child will then try to recognise the fruit and write its name in a specified place on the screen. On the click of a check button the name of the fruit written by the child will be checked by your program and if correct will reward the child with a suitable message. If the name presented by the child is not correct, a suitable message should be presented on a red background with the correct name of the fruit included in the message.
so far I have managed to create a form with 5 different fruit pictures and a text box below them. a button at the bottom of the form then checks the results and presents a message box to tell them if they have passed or failed.
Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResults.Click
If txtApple.Text = "APPLE" And txtOrange.Text = "ORANGES" And txtStrawberry.Text = "STRAWBERRIES" And txtGrapes.Text = "GRAPES" And txtBanana.Text = "BANANAS" Then
MsgBox("Congratulations! you got it all right!", MsgBoxStyle.OkOnly)
End
Else
MsgBox("Incorrect, please try again", MsgBoxStyle.OkOnly)
End
End If
End Sub
but I can't get it to randomise the picture of the fruit, so it only displays one fruit at a time and checks against it.
Any help is appreciated.
T开发者_如何转开发hanks
Check out the Random
class.
There's example on that page that
creates a single random number generator and calls its NextBytes, Next, and NextDouble methods to generate sequences of random numbers within different ranges.
Create a new instance of Random
(only do it the once - the reasons are explained on that page.):
Dim rand As New Random()
then
dim index = rand.Next(0, 5)
this will return a random value between 0 and 4. Use this index to choose which image to display. Repeat for the next image.
精彩评论