Click here to Skip to main content
15,799,017 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
OK guys I am to the point now I would just like to see this program run the way it need to gonna post the code I have not asking anybody to write it for me but give me some information and just let me know how bad my code looks I'm sure that I have several bad practices and such going on any info you can give me will be great. there is just a couple of thing that isn't work at the moment and that is in division the numbers are not working out to be evenly divisible

VB
Public Class Slection
    Inherits System.Windows.Forms.Form
    Private Sub gui_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        max_top.Hide()
        max_btm.Hide()
        lblDirections.Hide()
        Label1.Hide()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Gui.Show()
        Gui.Timer1.Enabled = True
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DDL.SelectedIndexChanged
        subject = DDL.SelectedIndex
        If check = 0 Then lblDirections.Show()
        max_top.Show()

        If check = 1 Then lblDirections.Show()
        max_top.Show()
        If check = 2 Then lblDirections.Show()
        max_top.Show()

        If check = 3 Then lblDirections.Show()
        max_top.Show()
        Label1.Show()
        max_btm.Show()

    End Sub
    Private Sub max_top_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles max_top.ValueChanged
        randnumtop = max_top.Value
    End Sub
    Private Sub max_btm_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles max_btm.ValueChanged
        randnum = max_btm.Value
    End Sub
    Public Sub time_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles time.ValueChanged
        myTime = (time.Value) * 60
    End Sub
End Class


VB
Public Class Gui
    Inherits System.Windows.Forms.Form
    Public Sub Getnew()
        usranswer.Text = ""
        usranswer.Focus()
        If Correct > 0 Then RightLabel.Show()
        If countTotal > 0 Then TotalLabel.Show()
        If Missed > 0 Then Missedlabel.Show()
        RightLabel.Text = Correct & "Correct"
        Missedlabel.Text = Missed & "Missed"
        TotalLabel.Text = countTotal & "Total"
    End Sub
    Private Sub gui_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initilize*********************************************
        FormBorderStyle = FormBorderStyle.FixedSingle
        Timer1.Enabled = True
        check = subject
        Slection.Hide()
        RightLabel.Hide()
        TotalLabel.Hide()
        Missedlabel.Hide()
        RightLabel.BackColor = Color.Transparent
        TotalLabel.BackColor = Color.Transparent
        Missedlabel.BackColor = Color.Transparent
        Select Case check
            Case "0"
                Me.signbox.Image = Image.FromFile("C:\value\add.png")
            Case "1"
                Me.signbox.Image = Image.FromFile("C:\value\sub.gif")
            Case "2"
                Me.signbox.Image = Image.FromFile("C:\value\mul.gif")
            Case "3"
                Me.signbox.Image = Image.FromFile("C:\value\div.gif")
        End Select
        'Count of Questions Total
        countTotal = 0
        'Count of Correct Answers
        Correct = 0
        'count of Wrong Answers
        Missed = 0
        'Start Problems
        If subject = 3 Then Call dproblem() Else 
        Call problem()
        Call Getnew()
    End Sub
    '**************************************************************
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case check
            Case "0"
                Call CheckAnswer_Add()
            Case "1"
                Call CheckAnswer_subtract()
            Case "2"
                Call CheckAnswer_Multiply()
            Case "3"
                Call CheckAnswer_Divide()
        End Select
        countTotal = Int(countTotal) + 1

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        End
        Me.Close()
    End Sub
    '***********************************************Timer & Progress Bar************************************************************************
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Interval = 1000
        myTime = myTime - 1
        TTLtxt.Text = myTime
        If myTime < 1 Then
            Timer1.Enabled = False
            MsgBox("Times Up!")
            MsgBox("Your score is :  " & (CInt(score) - CInt(points) & "%"))
            TTLtxt.Hide()
            My.Computer.FileSystem.WriteAllText("c:\value\value1.txt", "your Score is:" & score, False)
            Me.Close()
            Slection.Show()
        Else
        End If
        ProgressBar1.Maximum = (Slection.time.Value) * 59
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Enabled = False
        Else
            ProgressBar1.Value = ProgressBar1.Value + 1
        End If
            End Sub
End Class

VB
Module variables
    '*********************Delclrations**************************************************************
    Public answer, reply, countTotal, randnum, randnumtop, num1, num2, Correct, Missed, score, points, myTime As Integer
    Public RandomClass1 As New Random()
    Public check, subject, div As String
    '***********************************************************************************************
    '***********************!!!!!!!!!Formulas!!!!!!!!!*********************************************
    Public Sub CheckAnswer_Multiply()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 * num2)
    End Sub
    Public Sub CheckAnswer_Add()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 + num2)
    End Sub
    Public Sub CheckAnswer_subtract()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 - num2)
    End Sub
    Public Sub CheckAnswer_Divide()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 / num2)

    End Sub
    '********************************CHECKS***************************************************************
    Public Sub UC()
        If answer = reply Then Correct = Int(Correct) + 1
        If Int(answer) <> Int(reply) Then Missed = Int(Missed) + 1
        If Int(answer) <> Int(reply) Then MsgBox(CStr(answer), MsgBoxStyle.Information, Title:=("Wrong"))
        points = ((100 / CInt(countTotal)) * CInt(Missed))
        score = 100
        If countTotal = 100 Then MsgBox("Great work you have completed 100 questions")
    End Sub
    Public Sub dproblem()
        Dim dnum1 As Integer
        Dim dnum2 As Integer = RandomClass1.Next(1, randnumtop)
        Dim danswer As Integer = RandomClass1.Next(1, 10)
        dnum1 = dnum2 * answer
        Gui.TopNumLabel.Text = dnum1
        Gui.ConstantLabel.Text = dnum2
    End Sub
    Public Sub problem()
        'Get Random Numbers for Problem
        Gui.TopNumLabel.Text = RandomClass1.Next(randnumtop)
        Gui.ConstantLabel.Text = RandomClass1.Next(randnum)
        'Make sure top number bigger than bottom
        If Integer.Parse(Gui.TopNumLabel.Text) < Integer.Parse(Gui.ConstantLabel.Text) Then
            Call problem()
        Else
        End If
    End Sub
    Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer
        ' by making Generator static, we preserve the same instance '
        ' (i.e., do not create new instances with the same seed over and over) '
        ' between calls '
        Static RandomClass1 As System.Random = New System.Random()
        Return RandomClass1.Next(randnumtop, randnum)
    End Function
End Module
Posted
Updated 5-Mar-12 14:51pm
v2

You're looking at the problem backwards. If you want an evenly divisble problem, start with the answer and work backwards. In a problem of "X / Y = Z" Pick a random answer value (Z) and multiply it by your divisor (Y) to get X. The result is a very neatly divisible equation.
 
Share this answer
 
Comments
Member 8685789 2-Mar-12 12:20pm    
Dave thanks for the quick reply it sounds like a clean way to get what I am looking for but I'm very much a novice when it comes to coding in vb.net could you give me a piece of sample code to look at that would achieve that.
Dave Kreskowiak 2-Mar-12 12:55pm    
Seriously?? This is very simple math...

Dim RNG As New Random() ' Need a random number generator...

Dim num1 As Integer
Dim num2 As Integer = RNG.Next(1, 10) ' Will return 1 to 9...
Dim answer As Integer = RNG.Next(1, 100) ' Will return 1 to 99...

' For example, num2 = 5 and answer = 60
num1 = num2 * answer

' Output:
' 300 / 5 = 60
Console.WriteLine(String.Format("{0} / {1} = {2}", num1, num2, answer))

Of course, you'll have to modify the ranges in the RNG.Next calls to limit your problems to whatever you want.
Member 8685789 2-Mar-12 13:02pm    
Thanks again Dave gonna try to put this together and make it work. Yea seriously lol I think I have just been looking at this stuff and over thinking it for way to long. i know its simple math and I appreciate you patience and time
Dave Kreskowiak 2-Mar-12 13:34pm    
Everbody starts somewhere! After 30+ years of writing code, even I overthink stuff sometimes. Good Luck!
0) I gotta tell you that using the Call keyword is completely unnecessary in VB.Net.

1) I don't see where you mod code is in the code you posted.

2) I don't see any loops in your code.
 
Share this answer
 
Comments
Member 8685789 2-Mar-12 16:32pm    
took the mod out when I added
Public Sub dproblem()
Dim dnum1 As Integer
Dim dnum2 As Integer = RandomClass1.Next(1, randnumtop)
Dim danswer As Integer = RandomClass1.Next(1, randnum)
dnum1 = dnum2 * answer
Gui.TopNumLabel.Text = dnum1
Gui.ConstantLabel.Text = dnum2
End Sub
as far as a loop goes didn't think one would be need it when I call the get problem on button i guess that is where I am messing up

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900