|
-
Oct 5th, 2003, 07:29 AM
#1
Thread Starter
Fanatic Member
Would someone please check my function? [SOLVED]
VB Code:
Public Function ComparePlayerAnswer()
Dim SelectedAnswer, Msg As String
Dim IsCorrect As Boolean
Dim NumTries As Integer
NumTries = NumTries + 1
If IsCorrect = True Then
IsCorrect = False
End If
For i = 0 To frmQuestions.cmdChoice.Count - 1
If frmQuestions.cmdChoice(i).Value = True Then
SelectedAnswer = frmQuestions.cmdChoice(i).Caption
End If
Next i
If SelectedAnswer = QuestionArray(CurrentQuestion).Answer Then
Msg = "You are Correct."
IsCorrect = True
If NumTries = 1 Then
Msg = Msg & " 5 picks on the game board have now been granted to you."
Else
Msg = Msg & " 1 pick on the game board has now been granted to you."
End If
Else
MsgBox "Incorrect"
End If
If IsCorrect = True Then
MsgBox Msg
End If
End Function
For some reason, NumTries is resetting itself every time the program processes the function. As a result, it is displaying that it will give the player 5 picks on the game board when it should in fact only be giving 1.
Last edited by hothead; Oct 5th, 2003 at 08:57 AM.
-
Oct 5th, 2003, 08:08 AM
#2
Not NoteMe
Try making NumTries a global variable (or possible a static variable in that function).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Oct 5th, 2003, 08:17 AM
#3
Thread Starter
Fanatic Member
I never thought about that. Static will keep the value no matter what.
But won't it keep the value forever? I guess I could use a static variable to accomodate how many times the function has been run, then reset NumTries when it changes. Or go like this:
VB Code:
If NumTries = NumTries + 3 Then NumTries = 1
I shall try this. Thanks for the help.
-
Oct 5th, 2003, 08:56 AM
#4
Thread Starter
Fanatic Member
Thanks, your help worked out rather well.
-
Oct 5th, 2003, 02:33 PM
#5
So Unbanned
Uhm...
If NumTries = NumTries + 3 Then NumTries = 1
Will always be false.
Just as x=x+3, 0=3, 1=4, etc.
-
Oct 5th, 2003, 05:24 PM
#6
Thread Starter
Fanatic Member
Not if the variable is declared as Static. It will always keep its previous value. If the answer is wrong, it redoes the entire function from the beginning, so after a few times of redoing the function, keeping its value from the previous attempt, it will be true.
-
Oct 5th, 2003, 05:47 PM
#7
So Unbanned
Originally posted by hothead
Not if the variable is declared as Static. It will always keep its previous value. If the answer is wrong, it redoes the entire function from the beginning, so after a few times of redoing the function, keeping its value from the previous attempt, it will be true.
Uhm...
Regardless...
Whatever NumTries equals, NumTries will never equal NumTries + 3.
Just as 0 doesn't equal 3.
3 <> 6, 7 <> 10, etc.
-
Oct 5th, 2003, 06:10 PM
#8
Thread Starter
Fanatic Member
If you'll notice, I have a NumTries = NumTries + 1 at the beginning of the function.
A static variable will keep its previous setting. So if I set NumTries to 1 by default, it will increment this by 1 the next time around.
So....
Second time it'll be 2.
Third time it'll be 3.
See how it works?
Last edited by hothead; Oct 5th, 2003 at 06:21 PM.
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
|