PDA

View Full Version : key_down event



kunguito
07-12-2007, 06:59 AM
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.

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





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

blazonQC
07-30-2007, 06:55 PM
I know it's been a while since this post but..... is it throwing the error in the code:

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


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

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



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

Chad

kunguito
07-31-2007, 01:58 AM
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!!!

blazonQC
07-31-2007, 11:46 AM
It's no problem :) . Sorry it didn't work for you though! :(

Chad

kunguito
08-01-2007, 01:38 AM
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:help!