Showing results 1 to 10 of 10

Thread: Alarm object in vba of integration projectnot is not working for sub-projects

  1. #1
    Join Date
    29.07.2007
    Location
    Germany
    Posts
    192

    Frage Alarm object in vba of integration projectnot is not working for sub-projects

    Hey everybody,

    I do have a problem with the Alarm object in vba of an integration project.

    Using following code:

    Option Explicit
    Dim WithEvents zAlarm As Alarm
    
    'procedure is executed on startup of the zenOn runtime
    Private Sub Project_Active()
        'init the alarm object for events
        Set zAlarm = thisProject.Alarm
    End Sub
    
    'procedure is executed when an Alarm comes
    Private Sub zAlarm_AlarmComes(ByVal obItem As IAlarmItem)
        'print specific information to Debug window...
        Debug.Print obItem.Timecomes & " > " & obItem.Text
    End Sub
    
    'procedure is executed when an Alarm has gone
    Private Sub zAlarm_AlarmGoes(ByVal obItem As IAlarmItem)
        'print specific information to Debug window...
        Debug.Print obItem.Timegoes & " < " & obItem.Text
    End Sub
    
    'procedure is executed when an Alarm was acknowledged by a user
    Private Sub zAlarm_AlarmAcknowledged(ByVal obItem As IAlarmItem)
        'print specific information to Debug window...
        Debug.Print obItem.TimeAcknowledged & " | " & obItem.Text
    End Sub
    
    Private Sub zAlarm_AlarmListSelectionChanged(ByVal obItem As IAlarmItem)
        'print specific information to Debug window...
         Debug.Print "AlarmListSelectionChanged: " & obItem.Name & " - " & obItem.Projectname
    End Sub
    
    'procedure is executed on terminating the zenOn Runtime
    Private Sub Project_Inactive()
        'free the alarm object
        Set zAlarm = Nothing
    End Sub

    The problem is the events of zAlarm are only fired for alarms which are from variables located in the integration project not for the alarms of variables which are located in the sub-projects of the integration project!

    For example:

    I do have an alarm picture in the integration project showing alarms from variables of the integration project and the sub-projects. If I am selecting in the AML an alarm of the integration project "_AlarmListSelectionChanged" is fired. If I am selecting in the same picture an alarm of a sub-project nothing happens!

    I need to be able to react on all alarms of the sub-project within vba of the integration project!
    What am I doing wrong?

    Please advice.

    Thanks for any input!

    H.-P.

  2. #2
    robertf Gast

    Pfeil Re: Alarm object in vba of integration projectnot is not working for sub-projects

    Hello hp!

    Your question is the nearby the same as on 28th of April

    see: http://www.copadata.com/forums/showthread.php?t=280

    I thought i already answered this question...

    Take a closer look at the sample i already inserted...

  3. #3
    robertf Gast

    Default Re: Alarm object in vba of integration projectnot is not working for sub-projects

    Hello hp!

    The post ist maybe not visible (or something is wrong...)

    So here is my answer again:


    Here is a small Sample how to get the Alarm Events from SUB Projects:

    Dim WithEvents obALARM As Alarm
    Dim WithEvents obSubPrj As Project
    
    Private Sub obALARM_AlarmAcknowledged(ByVal obItem As IAlarmItem)
        Debug.Print "* " & obItem.Text & "  >> " & obItem.Projectname
    End Sub
    
    Private Sub obALARM_AlarmComes(ByVal obItem As IAlarmItem)
        Debug.Print "+ " & obItem.Text & "  >> " & obItem.Projectname
    End Sub
    
    Private Sub obALARM_AlarmGoes(ByVal obItem As IAlarmItem)
        Debug.Print "- " & obItem.Text & "  >> " & obItem.Projectname
    End Sub
    
    Private Sub obSubPrj_Inactive()
        Debug.Print "SUB Project is not longer available"
        'alarm events of this project are not fired until it is reinitialized
    End Sub
    
    Private Sub Project_Active()
        Set obSubPrj = Application.Projects.Item("SUB1")
        If Not obSubPrj Is Nothing Then
            Set obALARM = obSubPrj.Alarm
        End If
    End Sub
    
    Private Sub Project_Inactive()
        Set obALARM = Nothing
        Set obSubPrj = Nothing
    End Sub

    I hope it helps

  4. #4
    Join Date
    29.07.2007
    Location
    Germany
    Posts
    192

    Default AW: Alarm object in vba of integration projectnot is not working for sub-projects

    Thanks a lot for the quick answer Robert!

    There was something wrong with my account, and there for my previous post and your answer were not visible! Now my account got fixed.

    So it is not possible to have one alarm object in the integration project holding the information of all projects?
    I have to provide the necessary alarm objects for all sub projects and loop on project start through the project list to initialize them.

    The problem is the people who are adding sub projects are not allowed to edit the vba of the integration project, and for a new sub project "Dim WithEvents obALARMxyz As Alarm" have to be added!
    The integartion is done by a wizard. Is it possible to do the modification in vba of the integration project by the wizard?

    If not how would the integration project be affected if I provide about 300 to 400 alarm object on stock to cover the possible max number of sub projects.


    Regards,

    H.-P.

  5. #5
    robertf Gast

    Default Re: Alarm object in vba of integration projectnot is not working for sub-projects

    Hi hp!

    Quote Originally Posted by hp
    So it is not possible to have one alarm object in the integration project holding the information of all projects?
    I have to provide the necessary alarm objects for all sub projects and loop on project start through the project list to initialize them.
    Yes, that is correct!

    Quote Originally Posted by hp
    The problem is the people who are adding sub projects are not allowed to edit the vba of the integration project, and for a new sub project "Dim WithEvents obALARMxyz As Alarm" have to be added!
    The integartion is done by a wizard. Is it possible to do the modification in vba of the integration project by the wizard?
    Yes it is possible to do that within a wizard. The VBE can be used to interact with VBA...

    Here is a basic sample:
    Public Sub Test()
      InsertCode "SUB1"
    End Sub
    
    Public Sub InsertCode(strSubProject As String)
      Dim i As Integer
      Dim obVBProj As VBProject
      Dim obVBComp As VBComponent
      Dim strProjectName As String
      Dim strExistingCode As String
      Dim strNewCode As String
      Dim nLine As Long
      
      strProjectName = "ZROOF"
      Set obVBProj = MyWorkspace.VBE.VBProjects.Item(strProjectName)
        
      For i = 1 To obVBProj.VBComponents.Count
        'find "thisProject" - ClassModule
        Set obVBComp = obVBProj.VBComponents.Item(i)
        If obVBComp.Name = "thisProject" Then
          nLine = obVBComp.CodeModule.CountOfLines
          If obVBComp.CodeModule.Find(strSubProject, 1, 1, nLine + 1, 1) = True Then
            Debug.Print "Project name found in actual code..."
          Else
            Debug.Print "Code not found, insert new code..."
            'insert declaration
            nLine = obVBComp.CodeModule.CountOfDeclarationLines
            Call obVBComp.CodeModule.InsertLines(nLine + 1, "Dim Withevents obAlarm_" & strSubProject & " As Alarm")
            'insert Events
            nLine = obVBComp.CodeModule.CountOfLines
            Call obVBComp.CodeModule.InsertLines(nLine + 1, "Private Sub obAlarm_" & strSubProject & "_AlarmComes(ByVal obItem As IAlarmItem)")
            Call obVBComp.CodeModule.InsertLines(nLine + 2, "  'some code...")
            Call obVBComp.CodeModule.InsertLines(nLine + 3, "End Sub")
            Call obVBComp.CodeModule.InsertLines(nLine + 4, "'--- next one ---")
          End If
        End If
      Next i
    End Sub


    ATTENTION! Debugging within the VBE is not possible in all cases...


    .

  6. #6
    Join Date
    29.07.2007
    Location
    Germany
    Posts
    192

    Default AW: Alarm object in vba of integration projectnot is not working for sub-projects

    Hi Robert,

    So I will take a closer look at VBE!

    If I got you right it is possible to change just parts in then code of "thisProject".
    There are already a few hundred lines of code inside and they must remain untouched by the Wizard.

    What about the performance of the system if there are a few hundred alarm objects located in the integration project?

    Thanks again!

    H.-P.

  7. #7
    robertf Gast

    Default Re: Alarm object in vba of integration projectnot is not working for sub-projects

    Hi hp!

    Quote Originally Posted by hp
    If I got you right it is possible to change just parts in then code of "thisProject".
    There are already a few hundred lines of code inside and they must remain untouched by the Wizard.
    You can add, delete and change the code, this depeneds on how deep you want to step into VBE...

    Quote Originally Posted by hp
    What about the performance of the system if there are a few hundred alarm objects located in the integration project?
    The performance depends on the code you are executing within the events. If the events are used and the executed code has no loops or something what takes time, the you have an event-triggered application, where the perfromance is no problem.

    The performance is getting bad, when you use something like "Sleep" or anything else within the events, because while the event is blocked also the zenon Runtime will be blocked!

  8. #8
    Join Date
    29.07.2007
    Location
    Germany
    Posts
    192

    Default AW: Alarm object in vba of integration projectnot is not working for sub-projects

    So performace will not be the problem, since the events are basicly used to strart a zenon function or to set some variables.

    Just one more question:

    I have tried to set the alarm objects of the sub projects in the "Private Sub Project_Active()" of the integration project. But the Application object doesn't see the sub project when the event in the integration project is fired.

    For example:

    Private Sub ListProjects()
        Dim liZähler As Integer
        
        For liZähler = 0 To Application.Projects.Count - 1
            Debug.Print liZähler; ": " & Application.Projects.Item(liZähler).Name
        Next liZähler
    End Sub

    If the SUB is executed in "Private Sub Project_Active()" of the integration project only the integration project is printed.

    If I execute the SUB later on all projects are printed!

    How to initialize the alarm objects automatically on startup of the integration project?

    Thanx...

    H.-P.

  9. #9
    robertf Gast

    Default Re: Alarm object in vba of integration projectnot is not working for sub-projects

    This is a timing problem...

    the problem is, that the SUB Project is not initialized at this point, so you may call a Function over the AUTOSTART – Script in the ROOF Project to initialize the objects…

    liZähler... you can also write your posts in german if you prefer...

  10. #10
    Join Date
    29.07.2007
    Location
    Germany
    Posts
    192

    Default AW: Alarm object in vba of integration projectnot is not working for sub-projects

    So the AUTOSTART – Script in the ROOF Project will be fired after all sub projects are initialized?

    H.-P.

    Ps. Next time in German...

Similar Threads

  1. Replies: 3
    Last Post: 7th February 2008, 16:55
  2. Problem with new projects
    By tomaslipa in forum zenon Supervisor
    Replies: 9
    Last Post: 27th September 2007, 08:26
  3. start different projects on CE
    By sebastiank in forum zenon Operator
    Replies: 0
    Last Post: 25th September 2007, 08:14
  4. VBA Object Overview
    By robertf in forum VBA
    Replies: 0
    Last Post: 16th August 2007, 10:18
  5. Working with the 'Alarm' objects
    By robertf in forum VBA
    Replies: 0
    Last Post: 16th August 2007, 09:22

Posting Rules

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