Public Class Form1
    Dim sum As Integer      '宣告sum為成員變數，用來儲存積分

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sum = 10            '設定積分初始值為10
        Label4.Text = "積分：" & sum
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True       '啟動計時器
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '每0.1秒執行1次
        Randomize()
        Label1.Text = Int(Rnd() * 9) + 1    '每0.1秒，Label1~3的值變化1次
        Label2.Text = Int(Rnd() * 9) + 1
        Label3.Text = Int(Rnd() * 9) + 1
        '宣告count用來記錄計時器作用的次數
        Static count As Integer
        count = count + 1
        If count Mod 5 = 0 Then     '若條件成立，表示計時器已作用0.5秒
            Timer1.Enabled = False  '停止計時器，使Label1~3的值不再變化
            Call cal_point()        '呼叫計算積分的副程式
        End If
    End Sub

    Sub cal_point()
        If Label1.Text = Label2.Text And Label2.Text = Label3.Text Then
            sum = sum + 10  '3個數字相同+10分
        ElseIf Label1.Text = Label2.Text Or Label2.Text = Label3.Text Or
               Label1.Text = Label3.Text Then
            sum = sum + 2   '2個數字相同+2分
        Else
            sum = sum - 1   '數字都不同-1分
        End If
        Label4.Text = "積分：" & sum
    End Sub


End Class
