...

View Full Version : VB Random Number Help please



Quondam
10-16-2004, 03:08 AM
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

oracleguy
10-16-2004, 08:22 PM
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.

Quondam
10-17-2004, 12:37 AM
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

oracleguy
10-17-2004, 10:54 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum