-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.vb
217 lines (182 loc) · 9.63 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim Sex As String
Dim press1 As Double = 0
Dim press2 As Double = 0
Dim press3 As Double = 0
Dim pressStart As Double = 0
'Dim press2Start As Double = 0
'Dim press3Start As Double = 0
If RadioButton1.Checked Then Sex = "Male"
If RadioButton2.Checked Then Sex = "Female"
Dim rng As New Random
Dim arndint = rng.Next(2, 6)
If TimeOfDay >= #11:59:55 PM# Then
MsgBox("The current time is within 5 seconds of midnight" &
vbCrLf & "The timer returns to 0.0 at midnight")
Return
End If
Dim start, finish, totalTime As Double
Dim Msgboxstring As String
Msgboxstring = "Ready to begin?"
If (MsgBox(Msgboxstring, MsgBoxStyle.YesNo, "Science Project")) = MsgBoxResult.Yes Then
'Dim rng As New Random
arndint = rng.Next(2, 6)
start = Microsoft.VisualBasic.DateAndTime.Timer 'current time
finish = start + arndint 'Set end time for random duration.
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
' Do other processing while waiting for 5 seconds to elapse.
Loop
BackColor = Color.DeepSkyBlue 'time has passed, so change colour and start first timer
pressStart = Microsoft.VisualBasic.DateAndTime.Timer
'wait until the key is pressed
MsgBox("presskey", MsgBoxStyle.Critical, "Science!")
press1 = Microsoft.VisualBasic.DateAndTime.Timer - pressStart
Me.Label3.Text = Math.Round(press1, 4) 'update screen time
BackColor = Color.WhiteSmoke 'reset screen colour
End If
Msgboxstring = "Ready for next test?"
If (MsgBox(Msgboxstring, MsgBoxStyle.YesNo, "Science!")) = MsgBoxResult.Yes Then
'Dim rng As New Random
arndint = rng.Next(2, 6)
start = Microsoft.VisualBasic.DateAndTime.Timer 'current time
finish = start + arndint 'Set end time for random duration.
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
' Do other processing while waiting for 5 seconds to elapse.
Loop
BackColor = Color.DeepSkyBlue 'time has passed, so change colour and start first timer
pressStart = Microsoft.VisualBasic.DateAndTime.Timer
'wait until the key is pressed
MsgBox("presskey", MsgBoxStyle.Critical, "Science!")
press2 = Microsoft.VisualBasic.DateAndTime.Timer - pressStart
Me.Label4.Text = Math.Round(press2, 4) 'update screen time
BackColor = Color.WhiteSmoke 'reset screen colour
End If
Msgboxstring = "Ready for final test?"
If (MsgBox(Msgboxstring, MsgBoxStyle.YesNo, "Science!")) = MsgBoxResult.Yes Then
'Dim rng As New Random
arndint = rng.Next(2, 6)
start = Microsoft.VisualBasic.DateAndTime.Timer 'current time
finish = start + arndint 'Set end time for random duration.
Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
' Do other processing while waiting for 5 seconds to elapse.
Loop
BackColor = Color.DeepSkyBlue 'time has passed, so change colour and start first timer
pressStart = Microsoft.VisualBasic.DateAndTime.Timer
'wait until the key is pressed
MsgBox("presskey", MsgBoxStyle.Critical, "Science!")
press3 = Microsoft.VisualBasic.DateAndTime.Timer - pressStart
Me.Label5.Text = Math.Round(press3, 4) 'update screen time
BackColor = Color.WhiteSmoke 'reset screen colour
End If
'average times of key press
Dim pressAverage As Double = (press1 + press2 + press3) / 3
Me.Label6.Text = Math.Round(pressAverage, 4)
Me.Label6.Visible = True
Me.Label7.Visible = True
Me.Label8.Visible = True
Me.Label9.Visible = True
Me.Label10.Visible = True
Me.Label11.Visible = True
Me.ProgressBar1.Visible = True
Me.ProgressBar2.Visible = True
Dim myPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Science.csv"
My.Computer.FileSystem.WriteAllText(myPath,
vbCrLf & Me.TextBox1.Text & "," & Sex & "," & Me.CheckBox1.Checked & "," & Me.CheckBox2.Checked & "," & Me.CheckBox3.Checked & "," & press1 & "," & press2 & "," & press3 & "," & pressAverage, True)
'put the code for average progress bars here
'Dim myPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Science.csv"
Using MyReader As New Microsoft.VisualBasic.
FileIO.TextFieldParser(
myPath)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim totalRows As Short = 0
Dim largestNumber As Double = 0
Dim runningTotal As Double = 0
Dim ageOnRecord As Double = 0
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
Dim fieldCount As Short = 1
For Each currentField In currentRow
'processing of each of the fields goes here
If (fieldCount = 1) Then
ageOnRecord = Convert.ToInt32(currentField)
'MsgBox(ageOnRecord,, "ageOnRecord")
End If
If (fieldCount = 9) Then
If (ageOnRecord >= (Convert.ToInt32(Me.TextBox1.Text) - 3) And ageOnRecord <= (Convert.ToInt32(Me.TextBox1.Text) + 3)) Then
'MsgBox(Convert.ToInt32(Me.TextBox1.Text),, "textbox age")
'MsgBox(currentField,, "speed")
totalRows = totalRows + 1
runningTotal = runningTotal + currentField
If (currentField > largestNumber) Then
largestNumber = currentField
End If
End If
End If
fieldCount = fieldCount + 1
Next
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
"is not valid and will be skipped.")
End Try
End While
'MsgBox(totalRows,, "Total Rows")
'MsgBox(largestNumber,, "Largest Number")
'MsgBox(runningTotal,, "Total")
'MsgBox(runningTotal / totalRows,, "Average Value")
Me.Label8.Visible = True
Me.Label9.Visible = True
Me.Label9.Text = "Average: " & Math.Round(runningTotal / totalRows, 4)
Me.Label10.Visible = True
Me.Label10.Text = "Max: " & Math.Round(largestNumber, 4)
Me.Label11.Visible = True
Me.Label13.Visible = True
Me.Label14.Visible = True
Me.ProgressBar1.Visible = True
Me.ProgressBar2.Visible = True
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Maximum = largestNumber * 1000
Me.ProgressBar1.Value = (runningTotal * 1000) / totalRows
Me.ProgressBar2.Minimum = 0
Me.ProgressBar2.Maximum = largestNumber * 1000
Me.ProgressBar2.Value = pressAverage * 1000
End Using
MsgBox("Reset Form?", MsgBoxStyle.OkOnly, "Science!")
BackColor = Color.WhiteSmoke
Me.Label3.Text = 0
Me.Label4.Text = 0
Me.Label5.Text = 0
Me.Label9.Text = 0
Me.Label10.Text = 0
Me.TextBox1.Text = ""
Me.CheckBox3.CheckState = False
Me.CheckBox2.CheckState = False
Me.CheckBox1.CheckState = False
Me.RadioButton1.Checked = False
Me.RadioButton2.Checked = False
Me.Label6.Visible = False
Me.Label7.Visible = False
Me.Label8.Visible = False
Me.Label9.Visible = False
Me.Label10.Visible = False
Me.Label11.Visible = False
Me.Label13.Visible = False
Me.Label14.Visible = False
Me.ProgressBar1.Visible = False
Me.ProgressBar2.Visible = False
Me.ProgressBar1.Minimum = 0
Me.ProgressBar1.Maximum = 0
Me.ProgressBar1.Value = 0
Me.ProgressBar2.Minimum = 0
Me.ProgressBar2.Maximum = 0
Me.ProgressBar2.Value = 0
End Sub
End Class