RESOLVED Where can I move this code?
I am not very good at this and don't quite know how to word my question.
I have a program where the user selects the number of questions they want to be asked and then clicks the start button. When the start button is pressed the program checks how many questions the user is going to be asked and sets the variable. After this the start button is disabled and the user uses the next button for the next question.
What can I do with the question generation code so it is not contained within the start and next buttons click code?
As you can see the program just asks random multiplication questions.
Randomize
intResult1 = Int((12 * Rnd) + 1)
intResult2 = Int((12 * Rnd) + 1)
QuestionText.Caption = intResult1 & "X" & intResult2 & " ="
Thanks.
Re: Where can I move this code?
Create a Sub and call it as required:
VB Code:
Option Explicit
Private Sub Form_Load()
Randomize
End Sub
Private Sub xx()
Call Generate_Question
End Sub
Private Sub Generate_Question()
QuestionText.Caption = CStr(Int((12 * Rnd) + 1) & "X" & Int((12 * Rnd) + 1) & " =")
End Sub
Re: Where can I move this code?
Thank you very much. That works perfectly.
Re: RESOLVED Where can I move this code?
No probs.
A couple of points:
1. The Randomize only needs to be called once per session, hence I placed it in Form_Load(),
2. I did away with those intermediate variables, and
3. Cast the result as a String Data Type (CStr()) for the .Caption (not iperative to change from and Int to String, but good practice).
Re: RESOLVED Where can I move this code?
Thank you. It looks much nicer.