VB in Powerpoint, Expected Function or Variable
I'm trying to write a bit of code to work as a power point based test. When the user clicks on a radio button, the program would check to see if the correct one has been selected, then if correct answer has been selected add one to the score.
Here's the code:
Code:
Public TotalScore As Integer
Public Correct As Boolean
Public Sub OptionButton1_Click()
Correct = False
Run Answered()
End Sub
Public Sub OptionButton2_Click()
Correct = False
Run Answered()
End Sub
Public Sub OptionButton3_Click()
Correct = False
Run Answered()
End Sub
Public Sub Answered()
If (Correct = True) Then
TotalScore = TotalScore + 1
End If
End Sub
The problem comes up when the user clicks on one of the radio buttons it gives an error of "Compile Error: Expected Function or Variable".
Example: If the user clicks on OptionButton1, then the compile error pops up at Public Sub OptionButton1_Click(), so before any of the code has run.
I've not coded in Powerpoint before, and I'm not sure where this problem might come up at. Any idea's?
Re: VB in Powerpoint, Expected Function or Variable
http://www.vbforums.com/attachment.p...id=47243&stc=1
Based on your Subject, I've moved your thread to here.
Re: VB in Powerpoint, Expected Function or Variable
Re: VB in Powerpoint, Expected Function or Variable
I've been messing around with the code. I tried inserting breakpoints throughout the code, and it still errors before the OptionButton_click subroutine. I tried removing the Answered() portion (commented it out), and it runs fine then.
So I guess it's a problem with the Answered() subroutine. I'm not sure though what is going on there though, not sure what is wrong with the code.
Re: VB in Powerpoint, Expected Function or Variable
If this were VB6 you would just say Answered rather than Run Answered().
Re: VB in Powerpoint, Expected Function or Variable
I had tried that earlier, and it didn't like the code. It gave me an error of "= expected", so I added "Run" to the beginning and it accepted that.
Just removed run as well as the "correct =" line, and fed the value of Correct directly into the answered subroutine. Now it seems to work fine. Thank you for your help!
Code snippet below for anyone else who has this error pop up on them.
Code:
Private Sub RBtn3_Click()
Run Answered(False)
RBtn4.Caption = TotalScore
End Sub
Public Sub Answered(Correct As Boolean)
If (Correct = True) Then
TotalScore = TotalScore + 1
End If
End Sub
Re: VB in Powerpoint, Expected Function or Variable
This should also work.
Code:
Public Sub Answered(Correct As Boolean)
If Correct Then
TotalScore = TotalScore + 1
End If
End Sub