Results 1 to 6 of 6

Thread: Problems with the events caught by DoEvents and/or SlideShowNextSlide

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    3

    Post Problems with the events caught by DoEvents and/or SlideShowNextSlide

    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:
    Code:
    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:

    Code:
    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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problems with the events caught by DoEvents and/or SlideShowNextSlide

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    3

    Re: Problems with the events caught by DoEvents and/or SlideShowNextSlide

    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.

    Code:
    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problems with the events caught by DoEvents and/or SlideShowNextSlide

    Ironic, Jacob Roman just posted some code in CodeBank that is sure to improve
    the basic DoEvents for you. Look here.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2004
    Posts
    3

    Re: Problems with the events caught by DoEvents and/or SlideShowNextSlide

    Concerning the issue #2, I have finally done something which seems quite clean to me:

    Code:
    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. 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

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problems with the events caught by DoEvents and/or SlideShowNextSlide

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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