Public Class Form1 ' target number Dim target As Integer ' number of attempts Dim count As Integer ' start new game Sub ResetGame() target = 1 + Int(100 * Rnd()) count = 0 TrackBar1.Value = 1 Button2.Text = "Try " & TrackBar1.Value End Sub ' initialise Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Randomize() ResetGame() End Sub ' new game button Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ResetGame() End Sub ' exit button Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Application.Exit() End Sub ' scroll bar movement Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll Button2.Text = "Try " & TrackBar1.Value End Sub ' play button Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim diff As Integer = TrackBar1.Value - target count = count + 1 If (diff <= -10) Then MsgBox("Much too low", MsgBoxStyle.Information) ElseIf (diff <= -5) Then MsgBox("A little too low", MsgBoxStyle.Information) ElseIf (diff < 0) Then MsgBox("A fraction too low", MsgBoxStyle.Information) ElseIf (diff = 0) Then MsgBox("You got it in " & count & " tries!", MsgBoxStyle.Information) ResetGame() ElseIf (diff < 5) Then MsgBox("A fraction too high", MsgBoxStyle.Information) ElseIf (diff < 10) Then MsgBox("A little too high", MsgBoxStyle.Information) Else MsgBox("Much too high", MsgBoxStyle.Information) End If If (count = 5) Then MsgBox("You've used up your 5 goes. It was " & target & ". Start again.", MsgBoxStyle.Information) ResetGame() End If End Sub End Class