Public Class Form1

    Const FILE_BACKIMAGE1 As String = "PC演算処理速度計測ソフト1.txt"
    Const FILE_BACKIMAGE2 As String = "PC演算処理速度計測ソフト2.txt"
    Const READ_MEMO As String = "Readme.txt"
    Dim sett() As String '配列名
    Private Declare Function GetTickCount Lib "kernel32" () As Long

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()
        ListBox2.Items.Clear()
        ListBox3.Items.Clear()
        Dim StartTime As Long '開始時間
        Dim EndTime As Long '終了時間
        Dim M As Long
        Dim K As Long
        Dim X As Double 'ダミー計算用
        For M = 1 To 10
            StartTime = GetTickCount
            For K = 1 To 10000000
                X = X * 1.01
                X = X / 1.01
            Next K
            EndTime = GetTickCount
            ListBox1.Items.Add(EndTime - StartTime)


        Next M
        Dim kaisu As Long
        For kaisu = 0 To 9
            ListBox3.Items.Add(kaisu + 1 & "回目")
        Next kaisu

        Dim a As Integer '配列の番号
        Dim b As Decimal '合計の平均値
        Dim goukei As Long '足し算の結果
        For a = 0 To 9
            goukei += ListBox1.Items(a)
        Next
        b = goukei / 10
        TextBox1.Text = "平均値　　" & b '10回の平均値


        ReDim sett(5) '配列の要素を6個に設定
        sett(0) = "アプリケーションを全て閉じてから計測をやりなをしてください。"
        sett(1) = "タスクマネージャーを開いてCPU,メモリーの確認をしてください。"
        sett(2) = "Windows 7 を最適化して、パフォーマンスを向上させる ←ダブルクリックしてください。"
        sett(3) = "PC の速度を向上させる      ←ダブルクリックしてください。"
        sett(4) = "レジストリエラーの修正         ←ダブルクリックしてください。"
        If b < 80 Then
            TextBox2.Text = "良い"
        ElseIf 80.01 < b AndAlso b < 110 Then
            TextBox2.Text = "普通"
            ListBox2.Items.Add(sett(2))
            ListBox2.Items.Add(sett(3))
        ElseIf b > 110.01 Then
            TextBox2.Text = "悪い"
            ListBox2.Items.Add(sett(0))
            ListBox2.Items.Add(sett(1))
            ListBox2.Items.Add(sett(2))
            ListBox2.Items.Add(sett(3))
            ListBox2.Items.Add(sett(4))
        End If
    End Sub

    Private Sub opn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opn.Click
        ListBox1.Items.Clear()
        ListBox3.Items.Clear()
        TextBox2.Clear()

        Dim read As New IO.StreamReader(Application.StartupPath & "\" & "FILE_BACKIMAGE1")
        Dim dte() As String 'ファイルのデータ配列
        Dim line As String 'データの1行

        line = read.ReadLine
        dte = line.Split(",")
        TextBox1.Text = dte(0)
        TextBox2.Text = dte(1)
        ListBox1.Items.Add(dte(2) & "  の結果です、")
        ListBox1.Items.Add("平均値と評価のみ表示しています。")
        read.Close()

    End Sub
    Private Sub namesave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles namesave.Click
        WriteLog("FILE_BACKIMAGE1", "FILE_BACKIMAGE2")
    End Sub
    Private Sub WriteLog(ByVal FileName1 As String, ByVal FileName2 As String)

        Dim write1 As New IO.StreamWriter(FileName1)
        write1.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & (Now.ToString("yyyy\/MM\/dd")))

        write1.Close()
        Dim write2 As New IO.StreamWriter(FileName2, True)
        write2.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & (Now.ToString("yyyy\/MM\/dd")))
        write2.Close()
    End Sub

    Private Sub print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles print.Click
        PrintDocument1.Print()
    End Sub


    Private Sub printpre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printpre.Click
        PrintPreviewDialog1.ShowDialog()
    End Sub


    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim f As New Font("ＭＳ 明朝", 64, FontStyle.Bold)
        e.Graphics.DrawString(TextBox1.Text & "  " & TextBox2.Text, f, Brushes.Blue, 10, 10)
    End Sub
    Private Sub hist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hist.Click
        Process.Start("notepad.exe", "FILE_BACKIMAGE2")
    End Sub

    Private Sub endo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles endo.Click
        Me.Close()
    End Sub
    Private Sub ListBox2_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick
        Dim f As New Form2
        f.Owner = Me
        Dim i As Integer
        sett(0) = ""
        sett(1) = ""
        sett(2) = "http://windows.microsoft.com/ja-JP/windows7/Optimize-Windows-7-for-better-performance"
        sett(3) = "http://windows.microsoft.com/ja-JP/windows/explore/speed-up-your-pc"
        sett(4) = "http://www.systweak.com/registrycleaner/onlyad_new_Japanese.asp"
        If TextBox2.Text = "普通" Then
            i = Me.ListBox2.SelectedIndex
            f.WebBrowser1.Navigate(sett(i + 2))
        ElseIf TextBox2.Text = "悪い" Then
            i = Me.ListBox2.SelectedIndex
            If i = 0 Then
                Return
            ElseIf i = 1 Then
                Return
            Else

                f.WebBrowser1.Navigate(sett(i))
            End If
            End If

            f.Show()
    End Sub

    Private Sub バージョンToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles バージョンToolStripMenuItem.Click
        MsgBox(Application.ProductName & vbNewLine & Application.ProductVersion)
    End Sub

    Private Sub 説明書ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 説明書ToolStripMenuItem.Click
        Dim reader As New IO.StreamReader(Application.StartupPath & "\" & READ_MEMO, System.Text.Encoding.GetEncoding("shift-jis"))
        Dim f As New Form3
        f.Owner = Me
        f.TextBox1.Text = reader.ReadToEnd
        f.Show()
        f.TextBox1.DeselectAll()
    End Sub

    Private Sub 制作ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 制作ToolStripMenuItem.Click
        MsgBox("制作" & vbNewLine & "田中　裕之")
    End Sub
End Class
