Results 1 to 7 of 7

Thread: VB in Powerpoint, Expected Function or Variable

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2009
    Posts
    63

    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?

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2009
    Posts
    63

    Re: VB in Powerpoint, Expected Function or Variable

    Thank you!

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2009
    Posts
    63

    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.

  5. #5

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2009
    Posts
    63

    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

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width