AnyThing That Rockz
Home­FAQ­Search­Memberlist­Usergroups­Register­Log in
Post new topic   Reply to topicShare | 
 

 Simple Math Quiz

View previous topic View next topic Go down 
AuthorMessage
QuartzZapphyre
Admin


Posts: 29
Join date: 2008-08-15
Age: 19

PostSubject: Simple Math Quiz   Tue Mar 17, 2009 11:14 am

Option Explicit
Dim ans As String
Dim CorrectAnswer As Double
Dim tempNum As Integer

Sub Check()
If Val(lblCorrect.Caption) + Val(lblMistake.Caption) >= 10 Then
MsgBox "Thank you for playing!" & " Your Score is: " & lblCorrect.Caption & " out of 10 Questions", vbInformation, "Math Quiz"
ans = MsgBox("Do you want to play again...", vbQuestion + vbYesNo, "Math Quiz")
If ans = vbYes Then
'If the user chooses YES, reload the program
Unload Me
frmMain.Show
Else
'Once the user chooses NO, then END the program
End
End If
End If
Timer1.Enabled = False
End Sub
Sub Clear()
lblNum1.Caption = ""
lblNum2.Caption = ""
imgPicture.Picture = LoadPicture("")
txtAnswer.Text = ""
End Sub
Sub Randomize()
If optLevel1.Value = True Then
lblNum1.Caption = Int((10 - 1 + 1) * Rnd + 1)
lblNum2.Caption = Int((10 - 1 + 1) * Rnd + 1)
ElseIf optLevel2.Value = True Then
lblNum1.Caption = Int((100 - 10 + 1) * Rnd + 1)
lblNum2.Caption = Int((100 - 10 + 1) * Rnd + 1)
End If

If optSubtract.Value = True And lblNum1 < lblNum2 Then
tempNum = lblNum1
lblNum1 = lblNum2
lblNum2 = tempNum
End If
End Sub

Private Sub cmdCheck_Click()
If Not txtAnswer.Text = "" Then
If optAdd.Value = True Then
If txtAnswer.Text = Val(lblNum1) + Val(lblNum2) Then
imgPicture.Stretch = True
imgPicture.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Face05.ico")
lblCorrect.Caption = Val(lblCorrect) + 1
MsgBox "You got the correct answer!", vbInformation, "Math Quiz!"
Else
imgPicture.Stretch = True
imgPicture.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Face04.ico")
lblMistake.Caption = Val(lblMistake) + 1
MsgBox "Sorry, that's not the correct answer!", vbCritical, "Math Quiz!"
End If

ElseIf optSubtract.Value = True Then
If txtAnswer.Text = Val(lblNum1) - Val(lblNum2) Then
imgPicture.Stretch = True
imgPicture.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Face05.ico")
lblCorrect.Caption = Val(lblCorrect) + 1
MsgBox "You got the correct answer!", vbInformation, "Math Quiz!"
Else
imgPicture.Stretch = True
imgPicture.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Face04.ico")
lblMistake.Caption = Val(lblMistake) + 1
MsgBox "Sorry, that's not the correct answer!", vbCritical, "Math Quiz!"
End If
End If
Timer1.Enabled = False
lblTime.Caption = "10"
MsgBox "Get ready for the next question", vbInformation, "Math Quiz"
Call Clear
Call Check
Call Randomize
Timer1.Enabled = True
txtAnswer.SetFocus
Else
MsgBox "Blank Answer!", vbCritical, "Math Quiz"
Timer1.Enabled = True
End If

End Sub


Private Sub Form_Load()
ans = MsgBox("Are you ready to start ? Press the YES button to start the game!", vbInformation + vbYesNo, "Math Quiz!")
If ans = vbYes Then
Timer1.Enabled = True
Call Randomize
If optSubtract.Value = True Then
imgOperator.Stretch = True
imgOperator.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Misc19.ico")
Else
imgOperator.Stretch = True
imgOperator.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Misc18.ico")
End If
Else

End If
End Sub



Private Sub optAdd_Click()
imgOperator.Stretch = True
imgOperator.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Misc18.ico")
End Sub

Private Sub optLevel1_Click()
Call Randomize
End Sub

Private Sub optLevel2_Click()
Call Randomize
End Sub

Private Sub optSubtract_Click()
imgOperator.Stretch = True
imgOperator.Picture = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\Misc19.ico")
End Sub

Private Sub Timer1_Timer()
If Val(lblTime.Caption) <= 0 Then
If optSubtract.Value = True Then
CorrectAnswer = Val(lblNum1) - Val(lblNum2)
Else
CorrectAnswer = Val(lblNum1) + Val(lblNum2)
End If
MsgBox "Times Up!, the correct answer is " & CorrectAnswer, vbInformation, "Math Quiz!"
lblMistake.Caption = Val(lblMistake) + 1
Timer1.Enabled = False
Call Randomize
lblTime.Caption = "10"
Timer1.Enabled = True
Else
lblTime.Caption = lblTime - 1
End If
txtAnswer.SetFocus
Call Check
End Sub
=============================================================================




edit to your specifications lol! lol! lol! lol!
Back to top Go down
View user profile http://bugsoff.forumotion.net
 

Simple Math Quiz

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
BUGSoFF :: BUGS :: The Easy Way Out-
Post new topic   Reply to topic