'Trying to code an application involving random multiplication problems
I am trying to code a final project for my Visual Basic class due next Monday. I have been working on own, and I got pretty far, but now I am sadly stuck. I do not know how to progress any further. I have managed to correctly display the number of questions answered but the number correct vs. incorrect does not work properly. Almost all of my answers are marked incorrect despite being correct. Also, I would like some help on how to code the timer. I have never done so before. I want it to count up hours, minutes, and seconds.
I have attached a copy of my form design and I have included my code below. I also have comments detailing the name of the project and purpose above the option statements, but I left those out so my name wouldn't be on my submission.enter image description here
Option Explicit On
Option Strict Off
Option Infer Off
' Specifies the three required option statements.
Public Class frmMain
Dim random1 As New Random
Dim random2 As New Random
Dim random3 As New Random
Dim intAnswered As Integer = 0
Dim intCorrect As Integer = 0
Dim intIncorrect As Integer = 0
Dim intAnswer As Integer
Dim intSmartScore As Integer = 0
Public Sub CalculateMultiplication()
' Sub Procedure to create a random multiplication problem.
Dim intNum1 = random1.Next(2, 5)
Dim intNum2 = random2.Next(1, 5)
Dim intNum3 = random3.Next(6, 10)
lblNum1.Text = intNum1.ToString()
If intAnswered <= 5 Then
lblNum2Or3.Text = intNum2.ToString()
ElseIf intAnswered > 5 Then
lblNum2Or3.Text = intNum3.ToString()
End If
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Loads a random multiplication problem when the form is loaded.
CalculateMultiplication()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
' Closes the application when the exit menu item is clicked.
Me.Close()
End Sub
Private Sub txtAnswer_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtAnswer.KeyPress
' Accept only numbers and the backspace key.
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
intAnswered = intAnswered + 1
lblAnswered.Text = intAnswered
Dim intResult As Integer
intResult = Convert.ToInt32(txtAnswer.Text)
Dim intNum1 = random1.Next(2, 5)
Dim intNum2 = random2.Next(1, 5)
Dim intNum3 = random3.Next(6, 10)
lblNum1.Text = intNum1.ToString()
If intAnswered <= 5 Then
lblNum2Or3.Text = intNum2.ToString()
ElseIf intAnswered > 5 Then
lblNum2Or3.Text = intNum3.ToString()
End If
If intAnswered <= 5 Then
intAnswer = intNum1 * intNum2
ElseIf intAnswered > 5 Then
intAnswer = intNum1 * intNum3
End If
If intResult = intAnswer Then
intCorrect = intCorrect + 1
ElseIf intResult <> intAnswer Then
intIncorrect = intIncorrect + 1
End If
lblCorrect.Text = intCorrect.ToString
lblIncorrect.Text = intIncorrect.ToString
If intResult = intAnswer AndAlso intAnswered <= 5 Then
intSmartScore = intSmartScore + 5
ElseIf intResult <> intAnswer AndAlso intAnswered <= 5 Then
intSmartScore = intSmartScore - 5
ElseIf intResult = intAnswer AndAlso intAnswered > 5 Then
intSmartScore = intSmartScore + 15
ElseIf intResult <> intAnswer AndAlso intAnswered > 5 Then
intSmartScore = intSmartScore - 15
End If
lblSmartScore.Text = intSmartScore.ToString
txtAnswer.Text = String.Empty
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
