PDA

Click to See Complete Forum and Search --> : Problems with the events caught by DoEvents and/or SlideShowNextSlide


Raspoutim
Dec 7th, 2004, 02:18 PM
Hi all,
I'm currently working on an add-in for Powerpoint.
What I want to do is basically to send the title of the slides to a website during the slideshow.
For now, I have been able to do that but it appeared that it takes some time for the http calls, so I'd like to limit the sending to slides on which I stay for more than one second. (to allow to go quickly back and forth in the slideshow to find a slide for example)

So, I have this function:
Function Delay(nbSeconds As Double) As Boolean
Const OneSecond As Double = 1# / (1440# * 60#)
Dim endTime As Date

endTime = Now + OneSecond * nbSeconds
Do Until Now > endTime
Sleep 100
DoEvents
Loop
End Function

and in App_SlideShowNextSlide, I have:

index = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
Delay 1
If (index = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex) Then
MsgBox "send the title"
Call SendTitleFunction
End If


I have added the value 'index' because I haven't been able to stop the other function if the slide changes before the one second delay. So it checks if the slide has changed or not during the second.
If I go to the next slide with a click or the enter key, it's okay: I only send the correct one and I can go fast to a specific slide.
But if I use the arrows or next page or the space bar, I have to wait for the whole second: it seems that DoEvents don't catch these events.
Then to go backward I have to use the arrow or Previous Page, and I have to wait again (and to send the title...).

So, my questions are:
-is my assumption about DoEvents correct? and if so, is there a way to catch all slide changes?
-how could I tell to the Delay calls to stop once I change the current slide again to start another call? it seems that I have as many threads as slides changes in one second. I'm not sure that's good.

Thanks for your help!

R.

RobDog888
Dec 7th, 2004, 04:00 PM
Welcome to the Forums.

With the issue about #2, you can add a module level boolean variable that
you will check in the do loop. If it is true then you exit the do/procedure. If
its false then continue to wait. The way to set it would be in the KeyPress or
KeyDown events. But without seeing all your code I cant be certain which
event would be best.

The issue with #1 may be from the Sleep API call.

HTH

Raspoutim
Dec 7th, 2004, 06:10 PM
Thanks for welcoming and helping!

Actually, I have tried something like that and it didn't work. But, I'm a little confused about the behaviour of VBA with the different calls to the same function so I may have made a mistake.
The following code si the whole code included in a classe.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public WithEvents App As Application
Dim stopDelay As Boolean

Private Sub App_SlideShowNextSlide(ByVal wn As SlideShowWindow)
Dim index As Integer

index = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex

stopDelay = True ' not sure at all of that
Sleep 110 ' .....................
stopDelay = False '......................
Delay 1, index
End Sub

Function Delay(nbSeconds As Double, indexS As Integer) As Boolean

Const OneSecond As Double = 1# / (1440# * 60#)
Dim endTime As Date

endTime = Now + OneSecond * nbSeconds
Do Until Now > endTime
If (stopDelay) Then
Exit Function
End If
Sleep 100
DoEvents
Loop

Call SendTitleFunction

End Function


As I've written in the comment, I'm not sure at all of that, because I don't understand how VB manage the different calls to this class: basically, I don't know if the variable stopDelay is the same for all or not...

If it can help you better to see what I mean...

Thanks.

R.

RobDog888
Dec 7th, 2004, 08:24 PM
Ironic, Jacob Roman just posted some code in CodeBank that is sure to improve
the basic DoEvents for you. Look here. (http://www.vbforums.com/showthread.php?t=315416)

Raspoutim
Dec 8th, 2004, 06:54 PM
Concerning the issue #2, I have finally done something which seems quite clean to me:

Private Sub App_SlideShowNextSlide(ByVal wn As SlideShowWindow)
Dim index As Integer
index = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
Module1.nbDelays = Module1.nbDelays + 1 'nbDelays is a global boolean
Delay 2
If Module1.nbDelays = 0 Then
Call SendTitle
End If
End Sub

Function Delay(nbSeconds As Double) As Boolean
Const OneSecond As Double = 1# / (1440# * 60#)
Dim endTime As Date
endTime = Now + OneSecond * nbSeconds
Do Until Now > endTime
Sleep 100
DoEvents
Loop
Module1.nbDelays = Module1.nbDelays - 1
End Function

I don't really stop the other functions but it was not the real problem.

Concerning the other one, the one that matters to me :( I have followed your link and tried a little bit two of the functions mentionned: GetInputState and GetQueueStatus.
My computer crashed so I have lost it but it wasn't working as far as I remember. :cry: I will read the article again and try to eventually make it work...

BTW, do you know (it should maybe be a new topic) if there is a difference between VBA on Mac & Windows concerning the menu items? My Auto_Open function adds an item in the Tools menu but that doesn't work on a Mac although the addin is loaded.
Should I rewrite the addin in a Mac environment?

Thanks a lot for your help!

Raspoutim

RobDog888
Dec 8th, 2004, 08:21 PM
The link with the advanced DoEvents equilivalent, I'll admit, I have not tested out.

I have never developed anything for MAC, or seen the MAC version of Office.
I would cautiously "assume" that the event my not be firing due to
compatibility issues. So yes I would suggest that you develop OS platform
handeling for either MAC or Windows.

Start with a small test project to re-affirm the assumption so if its wrong,
your not wasting too much time. Could you post back or PM me if you find out?

Thanks.