Public Class Form1 Dim Answer As New List(Of String) Dim Question As New List(Of String) Dim Qcount As Integer Private Sub SetProblem() Qcount = Qcount + 1 If Qcount > Question.Count Then MsgBox("問題が1周したのでシャッフルして再出題します。") Answer.Clear() Question.Clear() LoadProblem() '問題を読み込む Qcount = 1 End If Label1.Text = Question(Qcount - 1) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load LoadProblem() '問題を読み込む SetProblem() '最初の問題を出題する Label2.Text = "答えを入力してください" Label3.Text = "問題" End Sub Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.Enter Then Button1.PerformClick() End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim g As Graphics = Me.CreateGraphics g.Clear(Color.Aqua) If TextBox1.Text = Answer(Qcount - 1) Then Dim p As New Pen(Color.Red) p.Width = 10 g.DrawEllipse(p, 70, 20, 230, 230) Else Dim p1 As New Pen(Color.Blue) p1.Width = 10 g.DrawLine(p1, 0, 0, 389, 280) g.DrawLine(p1, 0, 260, 370, 0) End If TextBox1.Clear() SetProblem() 'ここで次の問題を呼び出している。 End Sub Private Sub LoadProblem() Dim fileName As String = My.Application.Info.DirectoryPath & "\test.eng" Dim shiftJIS As System.Text.Encoding = System.Text.Encoding.GetEncoding("shift_jis") Dim lineNumber As Integer For Each line As String In IO.File.ReadAllLines(fileName, shiftJIS) If lineNumber Mod 2 = 0 Then Question.Add(line) Else Answer.Add(line) End If lineNumber += 1 Next '順番のシャッフル(ランダム出題)←必要なければまるごとコメントに Dim random As New Random For i As Integer = 0 To Question.Count - 1 Dim temp As String Dim r As Integer r = random.Next(0, Question.Count) temp = Question(i) Question(i) = Question(r) Question(r) = temp temp = Answer(i) Answer(i) = Answer(r) Answer(r) = temp Next End Sub End Class