Another Problem
Author |
Message |
krikor0322
![](http://www3.sympatico.ca/krikor/theworld.jpg)
|
Posted: Sun May 09, 2004 5:04 pm Post subject: Another Problem |
|
|
Basically the problem here is im trying to display the number of correct and incorrect answers, but for some reason it wont display, also im trying to figure out how to set a time limit, for example 1 min 30sec for this, and when the time is up it would display a msgbox saying "time up" or something like that, thanks, this is Visual Basic 6.0 btw
and also how would i be able to display the time left starting from 1min 30 sec in a txt box thanks again
Quote:
Dim correct As Integer
Dim incorrect As Integer
Private Sub cmdBack_Click()
frmIntroduction.Show
Unload Me
End Sub
Private Sub cmdCheck_Click()
If Timer1.Enabled = False Then
MsgBox "Click 'Go' to begin", , "Click 'Go'"
ElseIf Image1.Visible = True Then
Call one
ElseIf Image2.Visible = True Then
Call two
ElseIf image3.Visible = True Then
Call three
ElseIf Image4.Visible = True Then
Call four
ElseIf Image5.Visible = True Then
Call five
ElseIf Image6.Visible = True Then
Call six
ElseIf Image7.Visible = True Then
Call seven
ElseIf Image8.Visible = True Then
Call eight
End If
End Sub
Private Sub cmdGo_Click()
Timer1.Enabled = True
Image1.Visible = True
txtQuestion.Text = "(3^5) * (3^3) = 3^(5+3) = 3^8"
txtAnswer.Text = " "
End Sub
Sub one()
If txtAnswer.Text = 6561 Then
correct = correct + 1
txtQuestion.Text = "(5^8) / (5^3) = 5^(5)"
Image1.Visible = False
Image2.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "(3^5) * (3^3) = 3^(5+3) = 3^8 = 6561"
txtQuestion.Text = "(5^8) / (5^3) = 5^(5)"
Image1.Visible = False
Image2.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub two()
If txtAnswer.Text = 3125 Then
correct = correct + 1
txtQuestion.Text = "(4^3)^2 = 4^6"
Image2.Visible = False
image3.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "(5^8) / (5^3) = 5^(5) = 3125"
txtQuestion.Text = "(4^3)^2 = 4^6"
Image2.Visible = False
image3.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub three()
If txtAnswer.Text = 4096 Then
correct = correct + 1
txtQuestion.Text = "(3*2)^2 = (3^2)*(2^2)"
image3.Visible = False
Image4.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "(4^3)^2 = 4^6 = 4096"
txtQuestion.Text = "(3*2)^2 = (3^2)*(2^2)"
image3.Visible = False
Image4.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub four()
If txtAnswer.Text = 36 Then
correct = correct + 1
txtQuestion.Text = "(4/2) ^ 2 = (4^2) / (2^2)"
Image4.Visible = False
Image5.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "(3*2)^2 = (3^2)*(2^2) =36"
txtQuestion.Text = "(4/2) ^ 2 = (4^2) / (2^2)"
Image4.Visible = False
Image5.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub five()
If txtAnswer.Text = 4 Then
correct = correct + 1
txtQuestion.Text = "4^0"
Image5.Visible = False
Image6.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "(4/2) ^ 2 = (4^2) / (2^2) = 4"
txtQuestion.Text = "4^0"
Image5.Visible = False
Image6.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub six()
If txtAnswer.Text = 1 Then
correct = correct + 1
txtQuestion.Text = "(1/4)^ -2"
Image6.Visible = False
Image7.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "4^0 =1"
txtQuestion.Text = "(1/4)^ -2"
Image6.Visible = False
Image7.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub seven()
If txtAnswer.Text = 16 Then
correct = correct + 1
txtQuestion.Text = "25^(3/2)"
Image7.Visible = False
Image8.Visible = True
txtAnswer.Text = " "
Else
incorrect = incorrect + 1
MsgBox "(2/3) ^ -2 = (3/2) ^ 2"
txtQuestion.Text = "25^(3/2)"
Image7.Visible = False
Image8.Visible = True
txtAnswer.Text = " "
End If
End Sub
Sub eight()
If txtAnswer.Text = 125 Then
correct = correct + 1
MsgBox "done"
frmIntroduction.Show
Unload Me
Else
incorrect = incorrect + 1
MsgBox "done"
frmIntroduction.Show
Unload Me
End If
End Sub
Private Sub Form_Load()
correct = txtCorrect.Text
incorrect = txtIncorrect.Text
End Sub
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Tue May 11, 2004 11:24 pm Post subject: Re: Another Problem |
|
|
code: | Private Sub Timer1_Timer()
Static lngTime As Long
lngTime = lngTime + Timer1.Interval
lblTime.Caption = lngTime / 1000 & " seconds"
If lngTime >= 90000 Then
Timer1.Enabled = False
MsgBox "Time Up"
End If
End Sub |
Set Timer1.Interval to 1000 or something similar. That would be the easiest way to run the timer, but it's not perfect. (It wont time while the message boxes are up). A way to get around this would be to do something like this:
code: | Private dblTime As Double
Private Sub Form_Load()
dblTime = Timer
End Sub
Private Sub Timer1_Timer()
lblTime.Caption = Round(Timer - dblTime, 1) & " seconds"
If Timer - dblTime >= 90 Then
Timer1.Enabled = False
MsgBox "Time Up"
End If
End Sub |
You can set Timer1.Interval to as low as you want. There are other ways of cheating that code as well, and it'll mess up if the clock hits midnight. 8) But there are alternative ways of timing if you need something really accurate...
And I browsed through your code, and I think you forgot to have the number of incorrect/correct answers being displayed. Just add something like this:
txtCorrect.Text = correct
txtIncorrect.Text = incorrect
|
|
|
|
|
![](images/spacer.gif) |
krikor0322
![](http://www3.sympatico.ca/krikor/theworld.jpg)
|
Posted: Wed May 12, 2004 6:51 am Post subject: hey |
|
|
ya i figured out the score thing like 2 min after i posted lol, but i have another problem with this code, i need to have it in proper form, and that means no general declerations, i need to declare , correct, incorrect, and tries, in the command button and send it to the procedures, do you know how i can do that?? i gotta use byval or byref or something like that
|
|
|
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Wed May 12, 2004 2:00 pm Post subject: Re: hey |
|
|
code: | Private Sub cmdCheck_Click()
Static correct As Integer, incorrect As Integer, tries As Integer
If Timer1.Enabled = False Then
MsgBox "Click 'Go' to begin", , "Click 'Go'"
ElseIf Image1.Visible = True Then
Call one(correct, intcorrect, tries)
ElseIf Image2.Visible = True Then
Call two(correct, intcorrect, tries)
ElseIf image3.Visible = True Then
Call three(correct, intcorrect, tries)
ElseIf Image4.Visible = True Then
Call four(correct, intcorrect, tries)
ElseIf Image5.Visible = True Then
Call five(correct, intcorrect, tries)
ElseIf Image6.Visible = True Then
Call six(correct, intcorrect, tries)
ElseIf Image7.Visible = True Then
Call seven(correct, intcorrect, tries)
ElseIf Image8.Visible = True Then
Call eight(correct, intcorrect, tries)
End If
End Sub |
And you would declare your procedures like this: Sub one(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
You wouldn't actually have to put the 'ByRef' in there because it's passed that way automatically. Passing a variable ByRef passes the actual variable, while using ByVal creates a new memory location and a copy of the variable is passed.
|
|
|
|
|
![](images/spacer.gif) |
krikor0322
![](http://www3.sympatico.ca/krikor/theworld.jpg)
|
Posted: Wed May 12, 2004 4:17 pm Post subject: Okay |
|
|
Now that i got that working... I need access to those variables in the formload and another command button... how would i send it from the command button in which they are declared in... to the formload and the other command button....
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed May 12, 2004 4:26 pm Post subject: (No subject) |
|
|
you might want to make it a global varaible then. Otherwise you could decleara them as public and you should be able to access them as a method.
code: |
cmd_myButton.myVariable
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
krikor0322
![](http://www3.sympatico.ca/krikor/theworld.jpg)
|
Posted: Wed May 12, 2004 4:30 pm Post subject: Wellll |
|
|
See im supposed to code according to what weve learned in the class
is there a way i can send the variables to the procedure the command button calls... ???
and also... i was told i need to take the questions and answers from a text box instead of writing the answer and question in the code.. is there anyway thats possible?
by the way the code below doesnt work 100% notice at the bottom...
Private Sub cmdStop_Click()
Call stopme(correct, incorrect, tries)
End Sub
i love this place
code: |
Private Sub cmdBack_Click()
frmIntroduction.Show
Unload Me
End Sub
Private Sub cmdCheck_Click()
Static correct As Integer, incorrect As Integer, tries As Integer
txtCorrect.Text = correct
txtIncorrect.Text = incorrect
txtTries.Text = tries
imgGoodJOb.Visible = False
imgNextTime.Visible = False
If Timer1.Enabled = False Then
MsgBox "Click 'Go' to begin", , "Click 'Go'"
ElseIf Image1.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call one(correct, incorrect, tries)
ElseIf Image2.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call two(correct, incorrect, tries)
ElseIf image3.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call three(correct, incorrect, tries)
ElseIf Image4.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call four(correct, incorrect, tries)
ElseIf Image5.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call five(correct, incorrect, tries)
ElseIf Image6.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call six(correct, incorrect, tries)
ElseIf Image7.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call seven(correct, incorrect, tries)
ElseIf Image8.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call eight(correct, incorrect, tries)
ElseIf Image9.Visible = True Then
tries = tries + 1
txtTries.Text = tries
Call nine(correct, incorrect, tries)
End If
End Sub
Private Sub cmdGo_Click()
Timer1.Enabled = True
txtAnswer.Locked = False
Image1.Visible = True
txtQuestion.Text = "(3^5) * (3^3)"
cmdGo.Enabled = False
End Sub
Sub one(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 6561 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "(5^8) / (5^3)"
Image1.Visible = False
Image2.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(3^5) * (3^3) = 3^(5+3) = 3^8 = 6561", , "The Correct Answer Is"
txtQuestion.Text = "(5^8) / (5^3)"
Image1.Visible = False
Image2.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub two(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 3125 Then
imgGoodJOb.Visible = True
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "(4^3)^2"
Image2.Visible = False
image3.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(5^8) / (5^3) = 5^(5) = 3125", , "The Correct Answer Is"
txtQuestion.Text = "(4^3)^2"
Image2.Visible = False
image3.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub three(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 4096 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "(3*2)^2"
image3.Visible = False
Image4.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(4^3)^2 = 4^6 = 4096", , "The Correct Answer Is"
txtQuestion.Text = "(3*2)^2"
image3.Visible = False
Image4.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub four(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 36 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "(4/2) ^ 2"
Image4.Visible = False
Image5.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(3*2)^2 = (3^2)*(2^2) =36", , "The Correct Answer Is"
txtQuestion.Text = "(4/2) ^ 2"
Image4.Visible = False
Image5.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub five(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 4 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "4^0"
Image5.Visible = False
Image6.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(4/2) ^ 2 = (4^2) / (2^2) = 4", , "The Correct Answer Is"
txtQuestion.Text = "4^0"
Image5.Visible = False
Image6.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub six(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 1 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "(1/4)^ -2"
Image6.Visible = False
Image7.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "4^0 =1", , "The Correct Answer Is"
txtQuestion.Text = "(1/4)^ -2"
Image6.Visible = False
Image7.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub seven(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 16 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "25^(3/2)"
Image7.Visible = False
Image8.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(2/3) ^ -2 = (3/2) ^ 2", , "The Correct Answer Is"
txtQuestion.Text = "25^(3/2)"
Image7.Visible = False
Image8.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub eight(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 125 Then
correct = correct + 1
txtCorrect.Text = correct
txtQuestion.Text = "(5^2) * (5^3)"
Image8.Visible = False
Image9.Visible = True
imgGoodJOb.Visible = True
txtAnswer.Text = 0
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "25^(3/2) = 125", , "The Correct Answer Is"
txtQuestion.Text = "(5^2) * (5^3)"
Image8.Visible = False
Image9.Visible = True
imgNextTime.Visible = True
txtAnswer.Text = 0
End If
End Sub
Sub nine(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
If txtAnswer.Text = 3125 Then
correct = correct + 1
txtCorrect.Text = correct
imgGoodJOb.Visible = True
MsgBox "You got " & correct & " correct, and " & incorrect & " incorrect", , "Good Job!"
frmIntroduction.Show
Unload Me
ElseIf txtAnswer.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Else
incorrect = incorrect + 1
txtIncorrect.Text = incorrect
MsgBox "(5^2) * (5^3) = 3125", , "The Correct Answer Is"
imgNextTime.Visible = True
MsgBox "You got " & correct & " correct, and " & incorrect & " incorrect out of " & tries & " tries", , "Good Job!"
frmIntroduction.Show
Call endme(correct, incorrect, tries)
End If
End Sub
Private Sub cmdStop_Click()
Call stopme(correct, incorrect, tries)
End Sub
Private Sub Form_Load()
txtAnswer.Locked = True
End Sub
Sub endme(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
correct = 0
incorrect = 0
tries = 0
txtCorrect.Text = 0
txtIncorrect.Text = 0
txtTries.Text = 0
Unload Me
End Sub
Sub stopme(ByRef correct As Integer, ByRef incorrect As Integer, ByRef tries As Integer)
MsgBox "You got " & correct & " correct, and " & incorrect & " incorrect out of " & tries & " tries", , "Play Again Later!"
Unload Me
End Sub
|
|
|
|
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Thu May 13, 2004 11:08 pm Post subject: Re: Wellll |
|
|
Tony: You can't do that with procedures so far as I know. Also you would only use Public if you had multiple modules.
krikor: I'd recommend loading the questions and answers from an external text file. That way you'd only need one procedure to check the answer and record the points. Also, you can't pass your own variables to event procedures. If they need access to a variable, then declare it as global. Just ask if you need help loading the questions from a file.
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Mon May 17, 2004 5:07 pm Post subject: Re: yes!! |
|
|
Alright, here's some basic code which loads the questions & answers from a text file. I didn't add in all the options from your code, but this should show you how it's basically done. Place a label, command button, and a text box on a form to try it out. I made a text file of your questions so you can test it out (place in same directory). The first field is the question itself, the second field is the answer shown, and the third field is the actual answer. By the way... check the shown answer in question #7.
code: | Private strAnswer As String, intAnswer As Integer
Private intFileNum As Integer
Private Sub Command1_Click()
If Text1.Text = 0 Then
MsgBox "Oops! you forgot your answer", , "Enter An Answer!"
Exit Sub
ElseIf Text1.Text = intAnswer Then
MsgBox "Correct!"
Else
MsgBox strAnswer, , "The Correct Answer Is"
End If
Call DisplayQuestion
End Sub
Private Sub Form_Load()
intFileNum = FreeFile
Open App.Path & "\Questions.txt" For Input As #intFileNum
Call DisplayQuestion
End Sub
Private Sub Form_Unload(Cancel As Integer)
Close #intFileNum
End Sub
Private Sub DisplayQuestion()
Dim strQuestion As String
If EOF(intFileNum) = False Then
Input #intFileNum, strQuestion, strAnswer, intAnswer
Label1.Caption = strQuestion
Else
MsgBox "Quiz complete."
Label1.Caption = Empty
Command1.Enabled = False
End If
Text1.Text = 0
End Sub |
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Questions.txt |
Filesize: |
395 Bytes |
Downloaded: |
267 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
krikor0322
![](http://www3.sympatico.ca/krikor/theworld.jpg)
|
Posted: Mon May 17, 2004 6:44 pm Post subject: humm |
|
|
what format should the text be in??
can you post the exact way u have the questions typed in the text thanx
|
|
|
|
|
![](images/spacer.gif) |
Brightguy
![](http://compsci.ca/v3/uploads/user_avatars/527435178485ad4c287538.gif)
|
Posted: Mon May 17, 2004 7:55 pm Post subject: Re: humm |
|
|
Yeah, just download the Questions.txt file I attached in my previous post.
|
|
|
|
|
![](images/spacer.gif) |
krikor0322
![](http://www3.sympatico.ca/krikor/theworld.jpg)
|
Posted: Thu May 20, 2004 11:45 am Post subject: uhhh |
|
|
that works amazingly thanks alot... BUTTT i need to add the time aspect.. how would i do that??? so in 1 min the game ends..
basically u have 1 min to answer the questions
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu May 20, 2004 12:41 pm Post subject: (No subject) |
|
|
you create a timer with 60000 millisecond interval. After 60 seconds, timer event will be called and you place your "game over" code in there.
Or you could make interval 1000 and keep a counter of seconds left.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|
|