By failing to prepare, you are preparing to fail.
- Benjamin Franklin
News
Site News
Latest Comments
Affiliates
Proxies
Contribute!
Chat
Tutorials
Newest Articles
Most Popular
Highest Rated
Latest Comments
Code Samples
Newest Code
Most Popular
Highest Rated
Latest Comments
Blogs
Admins Blog
Newest Blogs
Most Popular
Highest Rated
Latest Comments
Forums
Latest Posts
Latest Topics
Memberlist
[login]
|
[Register]
Math Problems
by: bs0d
Description:
This program simply generates a random math problem that you can attempt to solve. - (6 labels, 5 buttons, 1 txt box).
Code:
Dim TRIES As Integer Private Sub cmdCheck_Click() 'Will set the count, and add one each time 'and apply it to this label im using to watch the count TRIES = TRIES + 1 lblCounter.Caption = TRIES 'Will calculate the percent if it gets answered correctly Percent = 1 / Val(TRIES) Percent = FormatPercent(Percent, 2) 'Will check to see if the answer matches If Val(txtGuess) = Val(lblAns.Caption) Then intRes = MsgBox("You guessed Correct!!", vbExclamation, "Correct!!") lblAns.Caption = Val(lblAns.Caption) lblPercent.Caption = Percent lblAns.Visible = True Else intRes = MsgBox("You guessed WRONG pal!", vbRetryCancel, "Wrong!!") txtGuess = "" txtGuess.SetFocus End If End Sub Private Sub cmdRandom_Click() 'Will generate a number between 1 and 10 Num1 = Int((10 - 1 + 1) * Rnd + 1) Num2 = Int((10 - 1 + 1) * Rnd + 1) lblRandom1.Caption = Val(Num1) lblRandom2.Caption = Val(Num2) 'Will generate a random number between 1 or 2 'if its 1, then we'll add, if its 2 then we'll multiply OPR = Int((2 - 1 + 1) * Rnd + 1) 'Will show the random operator in the label If Val(OPR) = 1 Then lblOperator.Caption = "+" Else lblOperator.Caption = "*" End If 'Will perform the random generated problem... If Val(OPR) = 1 Then lblAns.Caption = Val(Num1) + Val(Num2) Else lblAns.Caption = Val(Num1) * Val(Num2) End If 'Will hide the answer label until you get the 'answer correct,when you do - it will be visible. lblAns.Visible = False End Sub Private Sub Command1_Click() 'Will print the form PrintForm End Sub Private Sub Command2_Click() 'Will clear the entire form txtGuess = "0" lblRandom1.Caption = "" lblRandom2.Caption = "" lblOperator.Caption = "" lblAns = "" lblPercent.Caption = "" lblCounter.Caption = "" TRIES = 0 End Sub Private Sub Command3_Click() 'Will terminate the program End End Sub Private Sub Form_Load() 'Will center the form on the screen frmArithmetic.Top = (Screen.Height - frmArithmetic.Height) / 2 frmArithmetic.Left = (Screen.Width - frmArithmetic.Width) / 2 'Will generate a number between 1 and 12 Num1 = Int((12 - 1 + 1) * Rnd + 1) Num2 = Int((12 - 1 + 1) * Rnd + 1) lblRandom1.Caption = Val(Num1) lblRandom2.Caption = Val(Num2) 'Will generate a random number between 1 or 2 'if its 1, then we'll add, if its 2 then we'll multiply OPR = Int((2 - 1 + 1) * Rnd + 1) 'Will show the random operator in the label If Val(OPR) = 1 Then lblOperator.Caption = "+" Else lblOperator.Caption = "*" End If 'Will perform the random generated problem... If Val(OPR) = 1 Then lblAns.Caption = Val(Num1) + Val(Num2) Else lblAns.Caption = Val(Num1) * Val(Num2) End If 'Will hide the answer label until you get the 'answer correct,when you do - it will be visible. lblAns.Visible = False End Sub
No Comments for this page.
You Must be
signed in
or a
member
to comment.
Code Stats
15,569
Views
0
Total Comments
0
Rating of 5 (
3
Votes)
Code Options
·
Login to Rate This Code
·
Login to Post a Comment
·
Read more by this author
Related
·
RGB Color Fader
·
Adder
·
Cut and Paste
·
Combo Box Colors
·
Flag Viewer
"AllSyntax.com" Copyright © 2002-2021; All rights lefted, all lefts righted.
Privacy Policy