Public Class Form1 Const SR As Integer = 10 ' 行うセッションの数 Const PSec As Integer = 1 ' 強化子を呈示する秒数 Const VRAvg As Single = 6 ' VIの平均(sec) Const VRDev As Single = 0.4 ' VIの範囲(平均*範囲だけの誤差) Dim RftDuration As Integer ' 強化時間の測定用変数 Dim VIList(SR) As Single ' VIのリスト Dim ResList(SR) As Integer ' 反応回数のリスト Dim RTList(SR, 100 * Math.Ceiling(VRAvg + VRAvg * VRDev)) As Single ' 反応時間のリスト Dim NumOfRft As Integer ' 何回目のセッションか Dim resCnter As Integer ' セッション中何回目の反応か Dim userName As String ' 被験者の名前 Dim underExp As Boolean = False ' 実験中か Dim temp As Single = 0 ' セッション開始からの経過時間 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load endTotalSession() initialize() End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click RTList(NumOfRft, resCnter) = Microsoft.VisualBasic.Timer - temp resCnter = resCnter + 1 If Microsoft.VisualBasic.Timer >= temp + VIList(NumOfRft) Then Button1.Enabled = False PictureBox1.Visible = True ResList(NumOfRft) = resCnter resCnter = 0 RftDuration = 0 Timer1.Enabled = True End If End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick RftDuration = RftDuration + Timer1.Interval If RftDuration >= PSec * 1000 Then If NumOfRft >= SR Then Timer1.Enabled = False saveData() endTotalSession() Return End If NumOfRft = NumOfRft + 1 Timer1.Enabled = False Button1.Enabled = True PictureBox1.Visible = False temp = Microsoft.VisualBasic.Timer End If End Sub Private Sub saveData() Dim I As Integer = 0 FileOpen(1, "./response.log", OpenMode.Append) PrintLine(1, "name: " & userName) PrintLine(1, "date: " & DateTime.Now.ToString()) PrintLine(1, "VI list: " & SingleArray2str(VIList, ", ", 1)) For I = 1 To SR PrintLine(1, "") PrintLine(1, "session: " & I & " (required duration: " & VIList(I) & " sec)") PrintLine(1, "responses: " & ResList(I).ToString()) PrintLine(1, joinRTList(I, ", ")) Next PrintLine(1, "") FileClose(1) End Sub Private Function joinRTList(index As Integer, delim As String) Dim rstr As String = RTList(index, 0) Dim I As Integer = 1 Do Until RTList(index, I) = 0 rstr = rstr & delim & RTList(index, I) I = I + 1 Loop Return rstr End Function Private Function SingleArray2str(list() As Single, delim As String, Optional index As Integer = 0) Dim rstr As String = list(index) Dim I As Integer For I = index + 1 To list.Length - 1 rstr = rstr & delim & list(I) Next Return rstr End Function Private Sub initialize() Label1.Visible = True TextBox1.Visible = True Button2.Visible = True Button3.Visible = False NumOfRft = 1 underExp = False resCnter = 0 Randomize() RatioSet() End Sub Private Sub initialize2() Label1.Visible = False TextBox1.Visible = False Button2.Visible = False Label2.Visible = True Label3.Visible = True underExp = True End Sub Private Sub endTotalSession() Button3.Visible = True Label2.Visible = False Label3.Visible = False Button1.Visible = False PictureBox1.Visible = False End Sub Private Sub RatioSet() Dim r As Single For I = 1 To SR r = VRAvg - VRAvg * VRDev + (VRAvg * VRDev * 2) * Rnd() VIList(I) = r Next End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click If checkText() Then userName = TextBox1.Text initialize2() End If End Sub Private Function checkText() If TextBox1.Text = "" Or TextBox1.Text.Length < 4 Then Return False End If Return True End Function Private Sub sessionStart() temp = Microsoft.VisualBasic.Timer End Sub Private Sub Form1_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress If underExp Then If e.KeyChar = "s" Then Button1.Visible = True Label2.Visible = False Label3.Visible = False underExp = False sessionStart() End If End If End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click initialize() End Sub End Class