|
-
Jul 19th, 2009, 06:27 PM
#1
Thread Starter
Member
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?
-
Jul 19th, 2009, 06:55 PM
#2
Re: VB in Powerpoint, Expected Function or Variable

Based on your Subject, I've moved your thread to here.
-
Jul 19th, 2009, 07:36 PM
#3
Thread Starter
Member
Re: VB in Powerpoint, Expected Function or Variable
-
Jul 19th, 2009, 09:02 PM
#4
Thread Starter
Member
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.
-
Jul 19th, 2009, 09:17 PM
#5
Re: VB in Powerpoint, Expected Function or Variable
If this were VB6 you would just say Answered rather than Run Answered().
-
Jul 19th, 2009, 09:26 PM
#6
Thread Starter
Member
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
-
Jul 19th, 2009, 09:34 PM
#7
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
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
|