11 Replies Latest reply on Mar 25, 2011 1:42 PM by dhollebeek

    VBA Message "Can't enter break mode at this time"

    AlistairFrith

      I am repeatedly getting this message in my script, with options to "Continue", "End" and "Help" (I'll see what Help gives me... Ok, various reasons given but I don't think any of them apply). Any ideas why I might get this?

       

      The code is within a 'ContextChanged' event handler that I set up in the Display.Open event. The handler calls some routines from a .NET DLL that give access to AF and I think it may be one of these calls that triggers the error. I have breakpoints at the start and end of the event handler and the end one is what prompts the message. If I remove it, I don't get the message (unless I am stepping through the code) but the event handler is detached from the event and I have to run the Display.Open code again.

       

      I can obviously post the code if necessary but I don't have time right now. Let me know if it is needed.

       

       

       

      Thanks,

       

      --- Alistair.

        • Re: VBA Message "Can't enter break mode at this time"
          Ahmad Fattahi

          Alistair,

           

          Do you by any chance use Symbol.Remove in your code by any chance? There is a known issue recorded with identical symptoms as you are describing.

            • Re: VBA Message "Can't enter break mode at this time"

              Are you manipulating the VBProject using VBE?  You can trigger the VBA project to be reset using VBE (by changing the execution environment), which the debugger then spits out its dummy and doesn't let you continue to debug.

               

              I have also seen that if you put a DoEvents call before the offending line(s) that it resolves the (synchronisation) issue.

               

              Seen this a few times, some times you just need another way to debug...like using "debug.print" statements.

              • Re: VBA Message "Can't enter break mode at this time"
                AlistairFrith

                YesYesYes!

                 

                 

                 

                I have the following procedure, which I call in my event handler:

                 

                Private Sub clearLists()
                    ' Remove all the current list items
                    Dim s As Symbol
                    ThisDisplay.SelectedSymbols.RemoveAll
                    For Each s In ThisDisplay.Symbols
                        If (Left(s.name, 2) = "L_") Then
                            s.Selected = True
                        End If
                    Next s
                    Debug.Print "   Removing " & ThisDisplay.SelectedSymbols.Count & " symbols"
                    If ThisDisplay.SelectedSymbols.Count > 0 Then
                        If ThisDisplay.SelectedSymbols.Count > 1 Then
                            Set s = ThisDisplay.SelectedSymbols.Group
                        Else
                            Set s = ThisDisplay.SelectedSymbols(1)
                        End If
                        ThisDisplay.Symbols.Remove (s.name)
                    End If
                End Sub
                

                 I will try to find the known issue on the Support website. Is there a work-around?

                 

                --- Alistair.

                 

                 

                  • Re: VBA Message "Can't enter break mode at this time"
                    andreas

                    Hi Alistar,

                     

                    the known issue is not publicly available. As Rhys has mentioned, it is related to stepping through the code in debugging only. The only possible workaround is "not to step through removal code in the debugger".

                      • Re: VBA Message "Can't enter break mode at this time"
                        AlistairFrith

                        Oh, ok. So if I use debug.print rather than breakpoints, it should work? I'll do some more testing with no breakpoints at all and see if the behaviour is better...

                         

                        Hmm, I'll have to put more debug.print statements in. I think the event handler is still being un-registered.

                         

                        --- Alistair.

                          • Re: VBA Message "Can't enter break mode at this time"
                            AlistairFrith

                            The context handler seems to work until Value symbols are involved. Either adding or removing a value symbol seems to un-register the context handler. I have created some code to demonstrate the issue:

                             
                            Option Explicit
                            
                            Private WithEvents tmpCtxtHndlr As ContextHandler
                            
                            Private Sub Display_Open()
                                
                                If tmpCtxtHndlr Is Nothing Then
                                    Debug.Print "setting tmpCtxtHndlr"
                                    Set tmpCtxtHndlr = Application.ContextHandlers(4)
                                    Debug.Print "set tmpCtxtHndlr to " & tmpCtxtHndlr.Name & " - "; tmpCtxtHndlr.Description
                                Else
                                    Debug.Print "tmpCtxtHndlr is already set to " & tmpCtxtHndlr.Name & " - " & tmpCtxtHndlr.Description
                                End If
                                
                            End Sub
                            
                            Private Sub CreateText()
                                Dim symText As Text
                                
                                Debug.Print "Creating a Text symbol..."
                                Set symText = ThisDisplay.Symbols.Add(pbSymbolText)
                                symText.Contents = symText.Name
                                Debug.Print "...Created symbol: " & symText.Name
                            End Sub
                            
                            Private Sub CreateValue()
                                Dim symValue As Value
                                
                                Debug.Print "Creating a Value symbol..."
                                Set symValue = ThisDisplay.Symbols.Add(pbSymbolValue)
                                symValue.SetTagName ("sinusoid")
                                Debug.Print "...Created symbol: " & symValue.Name
                            End Sub
                            
                            Private Sub tmpCtxtHndlr_ContextChanged(FromDisplay As Display, FromContextHandler As ContextHandler)
                                Debug.Print vbCrLf & "========================" & vbCrLf & "Entered tmpCtxtHndlr_ContextChanged()"
                                Debug.Print "Context Changed to " & tmpCtxtHndlr.CurrentContext(FromDisplay)
                                
                                Call CreateText
                                
                                If tmpCtxtHndlr Is Nothing Then
                                    Debug.Print "Context handler has gone!"
                                Else
                                    Debug.Print "Context handler still there"
                                End If
                                
                                Debug.Print "Removing all symbols..."
                                Dim s As Symbol
                                For Each s In ThisDisplay.Symbols
                                    ThisDisplay.Symbols.Remove (s.Name)
                                Next s
                            
                                If tmpCtxtHndlr Is Nothing Then
                                    Debug.Print "Context handler has gone!"
                                Else
                                    Debug.Print "Context handler still there"
                                End If
                                
                                Debug.Print "Leaving tmpCtxtHndlr_ContextChanged()"
                            End Sub
                            

                            If you paste this into the ‘ThisDisplay’ code module of an empty element-relative display, and then try the following to reveal the issue:

                            1. Run Display_Open() to set up the context handler
                            2. Switch contexts a few times and watch the ‘Immediate’ window to ensure the handler works
                            3. Run CreateText() to create some text objects
                            4. Switch contexts a few times and ensure the handler still works (it will remove any created symbols)
                            5. Run CreateValue to create a value symbol
                            6. Switch contexts and note the context handler no longer fires after creating a value symbol outside of the context handler
                            7. Run Display_Open() and note that the context handler is re-assigned as it was set to Nothing
                            8. Switch contexts and note that the context handler fires
                            9. Switch contexts again and note that the context handler no longer fires after removing a value symbol inside the context handler

                            I have sent this to OSI support so if I get an answer, I will post it here.

                             

                            - Alistair.

                              • Re: VBA Message "Can't enter break mode at this time"
                                Ahmad Fattahi

                                Alistair,

                                 

                                There is currently no work around for your original problem; so may have to just avoid debugging that way. It would be great if you could update this thread for the record

                                  • Re: VBA Message "Can't enter break mode at this time"
                                    AlistairFrith

                                    The issue is not that I can't debug, it's that the event handler gets unregistered whether I am debugging or not! I.e. it will happen for the customer as well.

                                     

                                    OSI say this is a 'new' issue:

                                     

                                        Normal   0           false   false   false     EN-GB   X-NONE   X-NONE                                                                                                                                                                                                                                                                                                                                                        

                                     

                                    Hi Alistair,

                                     

                                     This is new issue and has not been resolved yet.

                                     

                                     Below is a (workaround:

                                     

                                    Private Sub Display_DataUpdate()

                                     

                                        Display_Open

                                     

                                    End Sub

                                     

                                     That way, when the value symbol gets data shortly after it is added, it resets the context handler.  The context handler ends up getting checked every 5 sec, but I think the performance impact of this should be minor.

                                     

                                    In fact, it's not just the event handler: the entire VBA environmrnt seems to get reset! I have a couple of global objects as well as the event handler(s) and they all get reset to Nothing. So after the context has been changed, potentially no VBA will work for the user for up to 5 seconds. This is quite a long way from ideal.

                                     

                                    --- Alistair.