Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB Random Number Help please

    This is my assignment, I am a bit stuck and need a jumpstart making the random ints appear as math problems in input boxes, please help

    You are to generate a math practice drill for elementary school students. These students need to practice their addition, subtraction and multiplication skills. The user will select the type of drill (enter either M for multiplication, S for subtraction or A for addition in a text box); the number of problems they wish to do (between 1 and 20 in another text box); and the high and low range to use for the drill (lowest number text box and highest number text box).

    Once user clicks the Start button, check to make sure all the values in the text boxes are entered correctly (correct alphabetic letter or numeric and within the ranges specified), display any error messages precisely indicating what is wrong in a Message label (one error per line) for each mistake and exit the click procedure resetting all the textboxes. If everything is correct, generate 2 random integers and display the problem with the appropriate symbol in an InputBox. Check the answer entered and keep track of how many correct answers are given. Continue generating new random numbers for the number of problems the user specified. When all the problems are answered, display the percentage correct in the Message label and exit the click procedure.



    Here is what I have so far.
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

    Dim strMath As String
    Dim intLow As Integer
    Dim intHigh As Integer
    Dim intNumProb As Integer
    Dim rndGenerator As New Random
    Dim intNum As Integer
    Dim intNum2 As Integer
    'Declare variables

    strMath = txtMath.ToString
    intLow = Convert.ToInt16(txtLow)
    intHigh = Convert.ToInt16(txtHigh)
    intNumProb = Convert.ToInt16(txtNumProb)

    intNum = rndGenerator.Next(intLow, intHigh)
    intNum2 = rndGenerator.Next(intLow, intHigh)

    If intNumProb < 1 or intNumProb > 20 || not intNumProb isnumeric then
    MessageBox.Show(" Data must be a number between 1 and 20")
    End If

    Select Case strMath
    Case "A"
    Case "M"
    Case "S"
    Case Else
    End Select

    End Sub

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    What part do you need help with? It looks like you know what you want, and got it setup, now you just need to do it.

    You are already generating the random numbers but I wouldn't do it there. Store the high, low, number of problems, and type in global variables or properties, which ever you prefer. Then have the start button validate all the data and store it, then kick off another form that shows the actual problems. Then make a generic sub called like NewProblem() that will do the following:

    • Increment the current problem number
    • Generate the random numbers
    • Update the form with all the information


    Then have a button like "Grade" or whatever that checks to see if the answer the user inputted is correct, if it is, remember it if you are doing any sort of scoring. Then call the NewProblem subroutine again if the current problem number does not equal the number of problems.
    OracleGuy

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its a tad difficult to explain whats going wrong, heres my new code(only a couple small changes), would you possibly be able to tell me what is incorrect please? its not runnig correctly the numbers coem out wrong.

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

    Dim strMath As String
    Dim intLow As Integer
    Dim intHigh As Integer
    Dim intNumProb As Integer
    Dim rndGenerator As New Random
    Dim intNum As Integer
    Dim intNum2 As Integer
    'Declare variables

    strMath = txtMath.ToString
    intLow = Convert.ToInt32(txtLow.Text)
    intHigh = Convert.ToInt32(txtHigh.Text)
    intNumProb = Convert.ToInt32(txtNumProb.Text)
    intNum = rndGenerator.Next(intLow, intHigh)
    intNum2 = rndGenerator.Next(intLow, intHigh)
    'Assing values to variables

    If intNumProb < 1 Or intNumProb > 20 Or Not IsNumeric(intNumProb) Then
    MessageBox.Show(" Data must be a number between 1 and 20")
    End If

    If Not IsNumeric(intLow) Then
    MessageBox.Show("Data must be numeric")
    End If

    If Not IsNumeric(intHigh) Then
    MessageBox.Show(" Data must be numeric")
    End If

    Select Case strMath
    Case "A"
    InputBox(Convert.ToString(intNum + intNum2))
    Case "M"
    InputBox(Convert.ToString(intNum * intNum2))
    Case "S"
    InputBox(Convert.ToString(intNum - intNum2))
    Case Else
    MessageBox.Show("Value must be A,S or M")
    End Select

    End Sub
    End Class

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Code:
    InputBox(intNum.ToString() & "+" & intNum2.ToString()))
    Is this the area where they aren't coming out right? It looks like it wouldn't, change your inputboxes to a similar fashion as above and see if that fixes it.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •