Consulting

Results 1 to 5 of 5

Thread: key_down event

  1. #1
    VBAX Regular
    Joined
    Jun 2007
    Posts
    67
    Location

    key_down event

    I am trying to do something that may look peculiar. The purpose of my little program is to learn vocabulary, combining a picture and a text that is prompted some seconds after the image and that represents it.

    In Powerpoint (Yes I'm aware that there's a section for that),
    I want to run a SlideShow and then without any control or form on the slides, depending on the key pressed Y/N.
    (Yes:I know this word so there is no need to display it any more)
    (No: Ohh, **** I don't remember it)
    And then propmt a random slide.

    Well my problem is that I don't think Powerpoint allows me to generate some kind of Key_Down event. This is what I tried:
    Go directly to DataEntered_KeyDown(), when I run it says that the type hasn't been defined by the user.

    [vba]Private numSlides As Integer
    Private NewId As Long
    Private qSlides() As Long 'Dynamically created
    'This is the main program
    Public Sub RandomSlideShow()
    Call IdentifierSlides
    'Establish the options for the SlideShow
    With ActivePresentation.SlideShowSettings
    .AdvanceMode = ppSlideShowManualAdvance
    .LoopUntilStopped = msoTrue
    .Run 'Start SlideShow
    End With
    End Sub

    Public Sub DataEntered_KeyDown(ByVal KeyCode As MSForms.ReturnInteger)

    If KeyCode = vbKeyY Then
    'delete the slideID from the array
    Call DeleteSlideIndex(qSlides(), NewId)
    ElseIf KeyCode = vbKeyN Then
    'Nothing
    ElseIf KeyCode = vbKeyESC Then
    'Abort the presentation
    Else

    End If

    'generate a random ID from the array
    NewId = GenerateNewID
    'Go to new slide
    With SlideShowWindows(1).View
    .GotoSlide NewId, msoFalse
    End With
    End Sub

    Private Sub DeleteSlideIndex(MyArray() As Long, Index As Integer)
    Dim I As Integer
    For I = Index To UBound(MyArray) - 1
    MyArray(I) = MyArray(I + 1)
    Next I
    ReDim Preserve MyArray(UBound(MyArray) - 1)
    End Sub

    Private Sub IdentifierSlides()
    numSlides = ActivePresentation.Slides.Count 'Counts the number of Slides of the presentation
    ReDim qSlides(1 To numSlides) As Long
    'Store the index of every slide in qSlides
    For I = 1 To numSlides
    qSlides(I) = ActivePresentation.Slides.Item(I).SlideID
    Next
    End Sub

    Public Function GenerateNewID(MyArray() As Long)
    Dim num As Integer
    'Changes the seed of the randomization
    Randomize
    num = Int((UBound(MyArray) - LBound(MyArray) + 1) * Rnd + LBound(MyArray))
    GenerateNewID = MyArray(num)
    End Function

    [/vba]



    I start to be annoyed by powerpoint, so maybe it's better I try it on Flash, what do you think? Any other suggestion

  2. #2
    VBAX Regular
    Joined
    Jul 2007
    Posts
    19
    Location
    I know it's been a while since this post but..... is it throwing the error in the code:

    [VBA]If KeyCode = vbKeyY Then
    'delete the slideID from the array
    Call DeleteSlideIndex(qSlides(), NewId)
    ElseIf KeyCode = vbKeyN Then
    'Nothing
    ElseIf KeyCode = vbKeyESC Then
    'Abort the presentation
    Else

    End If
    [/VBA]

    ? If so, try to use the actual codes instead:

    [VBA]If KeyCode = 89 Then
    'delete the slideID from the array
    Call DeleteSlideIndex(qSlides(), NewId)
    ElseIf KeyCode = 78 Then
    'Nothing
    ElseIf KeyCode = 27 Then
    'Abort the presentation
    Else

    End If
    [/VBA]


    If not, where exactly is the program breaking and giving you that error?

    Chad
    Office Version: 2000/2003
    Experience(Office): Amatuer
    Experience(VB): Veteran (Pre-VB6)
    Weakness: Formulae & New Object Properties
    Strengths: VB Syntax & Obscure Problem Solving

    "Als slechts ik Nederlands was, zou ik kunnen begrijpen wat ik zei! Kunt u me helpen?"
    "Koekje iedereen?"

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    67
    Location

    Return integer

    I guess the error was that nothing such as MSForms.ReturnInteger exists. So I changed it to Integer.
    It doesn't give any error but still the program doesn't do what I'd like.


    Thanks to reply to such an old post!!!

  4. #4
    VBAX Regular
    Joined
    Jul 2007
    Posts
    19
    Location
    It's no problem . Sorry it didn't work for you though!

    Chad
    Office Version: 2000/2003
    Experience(Office): Amatuer
    Experience(VB): Veteran (Pre-VB6)
    Weakness: Formulae & New Object Properties
    Strengths: VB Syntax & Obscure Problem Solving

    "Als slechts ik Nederlands was, zou ik kunnen begrijpen wat ik zei! Kunt u me helpen?"
    "Koekje iedereen?"

  5. #5
    VBAX Regular
    Joined
    Jun 2007
    Posts
    67
    Location
    I think I know what's up. But I don't know how to solve it.
    DataEnetered_KeyDown is not used by any other Sub or function. It should work as an event of the keyboard.

    I think that since I don't have any form I can't generate in PowerPoint a keyboard event.

    So Obviuosly the question is: How to build an independent sub that responds to keyboard events.

    There is a very taky solution: Include a loop until condition at the bottom the main program. But then I wouldn't be exploiting the driven by event characteristics of VBA.

    It starts to look like a philosophical issue!

    Thanks!

Posting Permissions

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