Youtube video - (If the embedded video doesn't appear, use this external link: https://youtu.be/J1RaU9vLXf4) -
Public
Class
frmGrammar
''' <summary>
''' Used to stop questions being randomly repeated
''' </summary>
''' <remarks></remarks>
Private
_used
As
List(Of
Integer
)
Property
indicesUsed()
Get
Return
End
Set
(
ByVal
value
))
_used = value
''' Constructor
''' <param name="r"></param>
''' <param name="used"></param>
''' <remarks>Selects a random question and puts the multi-choice answers in labels</remarks>
Sub
New
r
Random,
used
InitializeComponent()
Dim
lines()
String
= My.Resources.quiz.Split(
() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
If
used.Count = lines.Length
Then
used.Clear()
i
= r.
Next
(0, lines.Length)
While
used.Contains(i)
i = r.
used.Add(i)
indicesUsed = used
parts()
= lines(i).Split(
":"
c)
s1
= parts(0).Substring(0, parts(0).IndexOf(
"{"
s2
= parts(0).Substring(parts(0).IndexOf(
"}"
) + 1)
s3
) + 1, parts(0).IndexOf(
) - parts(0).IndexOf(
) - 1)
words()
= s3.Split(
"|"
Label1.Text = s1 &
"_____"
& s2
labels()
Label = {Label2, Label3, Label4, Label5}
For
x
= 0
To
3
x <= words.GetUpperBound(0)
labels(x).Text = words(x)
Else
labels(x).Text =
""
labels(x).Visible =
False
w
= Label6.Width + Label7.Width
labels(x).Text <>
w += labels(x).Width + 6
w -= 6
xp
= (
Me
.ClientSize.Width - w) \ 2
Label6.Left = xp
labels(0).Left = Label6.Right
= 1
labels(x).Left = labels(x - 1).Right + 6
Label7.Left = labels(x).Right
correctAnswer =
CInt
(parts(1))
'Stop
correctAnswer
selectedAnswer
''' btnPass
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>Clicked when user declines question</remarks>
btnPass_Click(
sender
System.
Object
,
e
System.EventArgs)
Handles
btnPass.Click
.DialogResult = Windows.Forms.DialogResult.Cancel
''' btnSolve
''' <remarks>Form.DialogResult depends on whether the answer is correct</remarks>
btnSolve_Click(
btnSolve.Click
selectedAnswer = correctAnswer
Label8.Text =
"✔"
Label8.Refresh()
Threading.Thread.Sleep(500)
.DialogResult = Windows.Forms.DialogResult.Yes
"X"
.DialogResult = Windows.Forms.DialogResult.No
''' Labels_Click
''' <remarks>Onclick the Label forecolor and fontsize changes.
''' This resets all of the other labels, so only one appears selected.
''' Adjust locations to centre multi-choice Labels in Form</remarks>
Labels_Click(
Label5.Click, Label4.Click, Label3.Click, Label2.Click
labels(x).ForeColor = Color.Silver
labels(x).Font =
Font(labels(x).Font.FontFamily, 10)
labels(x).Top = 109
= Array.IndexOf(labels, sender)
selectedAnswer = i
labels(i).ForeColor = Color.SteelBlue
labels(i).Font =
Font(labels(i).Font.FontFamily, 14)
labels(i).Top = 125 - labels(i).Height + 3
btnSolve.Enabled =
True
frmMaths
dt
DataTable
operands(,)
= {{
"+"
"-"
}, {
"/"
"*"
}}
''' <remarks>Sets up NumericUpDown1.TextChanged
''' Formulates a random equation string with a hidden value
''' </remarks>
Random)
AddHandler
DirectCast
(NumericUpDown1.Controls(1), TextBox).TextChanged,
AddressOf
txtChanged
i1
(2, 11)
i2
i3
Do
i2 = i1
i2 = r.
(1, 11)
Loop
i3 = i1
Or
i3 = i2
i3 = r.
= operands(0, r.
(0, 2)) &
" "
& i1.ToString
= operands(1, r.
& i2.ToString
& i3.ToString
x = r.
(1, 101)
s4
=
.Format(
"((({0} {1}) {2}) {3})"
, x, s1, s2, s3)
CDec
(dt.Compute(s4,
Nothing
Mod
1 <> 0
s4 =
Label1.Text =
"x {0} {1} {2}"
, s1, s2, s3) &
" = "
&
)).ToString
correctAnswer = x
''' Pass Button
''' <remarks>Clicked if user declines the question</remarks>
''' Solve Button
(NumericUpDown1.Value) = correctAnswer
''' NumericUpDown1.ValueChanged
''' <remarks>Enables/disable btnSolve depending if NumericUpDown1.Value > 0D</remarks>
NumericUpDown1_ValueChanged(
NumericUpDown1.ValueChanged
btnSolve.Enabled = NumericUpDown1.Value > 0D
''' NumericUpDown1.TextChanged
''' <remarks>Enables/disable btnSolve depending if NumericUpDown1.Value > 0</remarks>
txtChanged(
tb
TextBox =
(sender, TextBox)
btnSolve.Enabled = Val(tb.Text) > 0
''' Details1.Resize
''' <remarks>Resizes Form when the dropdown calculator is shown/hidden</remarks>
Details1_Resize(
Details1.Resize
.Height = 205 + Details1.Height