|
-
Jun 22nd, 2006, 05:44 PM
#1
Thread Starter
Junior Member
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.
Last edited by Crazy Spas; Jun 22nd, 2006 at 05:53 PM.
-
Jun 22nd, 2006, 05:48 PM
#2
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
-
Jun 22nd, 2006, 05:53 PM
#3
Thread Starter
Junior Member
Re: Where can I move this code?
Thank you very much. That works perfectly.
-
Jun 22nd, 2006, 06:04 PM
#4
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).
-
Jun 22nd, 2006, 06:07 PM
#5
Thread Starter
Junior Member
Re: RESOLVED Where can I move this code?
Thank you. It looks much nicer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|