Computer Science Canada Another Problem |
Author: | krikor0322 [ 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 |
Author: | Brightguy [ Tue May 11, 2004 11:24 pm ] | ||||
Post subject: | Re: Another Problem | ||||
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:
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 |
Author: | krikor0322 [ 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 |
Author: | Brightguy [ Wed May 12, 2004 2:00 pm ] | ||
Post subject: | Re: hey | ||
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. |
Author: | krikor0322 [ 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.... |
Author: | Tony [ Wed May 12, 2004 4:26 pm ] | ||
Post 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.
|
Author: | krikor0322 [ 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
|
Author: | Brightguy [ 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. |
Author: | Brightguy [ 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.
|
Author: | krikor0322 [ 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 |
Author: | Brightguy [ Mon May 17, 2004 7:55 pm ] |
Post subject: | Re: humm |
Yeah, just download the Questions.txt file I attached in my previous post. |
Author: | krikor0322 [ 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 |
Author: | Tony [ Thu May 20, 2004 12:41 pm ] |
Post 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. |