Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls"
'#Uses "..\classes\LinSchedule.cls"
'#Uses "..\classes\LinFrame.cls"
'#Uses "..\classes\LinSignal.cls"
'#Uses "..\classes\LinNode.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "Include.inc"

Option Explicit

'*****************************************************************************
' Module:
'        LIN
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'LIN'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev.    Author       Date           Description
'        ---------------------------------------------------------------------
'        1.0     Raja        30.05.2005     LIN for Pegasus lite XC164CM
'
'*****************************************************************************

Dim NodKey      As Integer
Dim SigKey      As Integer
Dim FrmKey      As Integer
Dim SchKey      As Integer
Dim Sch         As Integer
Dim SPubCount   As Integer
Dim SSubCount   As Integer
Dim iArrayCount As Integer
Dim iFrmAccount As Integer
Dim iMaxFrm     As Integer
Dim p           As New DAvECollection
Dim s           As New DAvECollection
Dim n           As New DAvECollection
Dim st          As New DAvECollection


'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As peripherals) As Boolean
    On Error GoTo OnLoadError

    Dim r As ProjectData
    Set r = ps.ProjectData
    
    
    If (r.v("LIN_ScheduleList_EXIST")) Then
        Set st = ObjectCollection("LinSchedules")
    End If

    If (r.v("LIN_FrameList_EXIST")) Then
        Set p = ObjectCollection("LinFrames")
    End If
    
    If (r.v("LIN_SignalList_EXIST")) Then
        Set s = ObjectCollection("LinSignals")
    End If
    
    If (r.v("LIN_NodeList_EXIST")) Then
        Set n = ObjectCollection("LinNodes")
    End If
    
    OnLoad = False

    '-------------------------------------------------------------------------
    ' page: General
    '-------------------------------------------------------------------------
    If (Not OnLoadPageGeneral(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Node
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNode(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Signal
    '-------------------------------------------------------------------------
    If (Not OnLoadPageSignal(ps)) Then Exit Function
    '-------------------------------------------------------------------------
    ' page: Frame
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFrame(ps)) Then Exit Function
    '-------------------------------------------------------------------------
    ' page:Schedule
    '-------------------------------------------------------------------------
    If (Not OnLoadPageSchedule(ps)) Then Exit Function
    '-------------------------------------------------------------------------
    ' page:Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' End of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "LIN\Dialog")) Then Exit Function

    OnLoad = True
    Exit Function

OnLoadError:
errorbox "Error", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As peripherals, Page As Integer, PageName As String) As Boolean
    On Error GoTo OnChangingPageError
    Dim sVarPre As String
    sVarPre = "LIN"

    OnChangingPage = False

    
    '-------------------------------------------------------------------------
    'page: General
    '-------------------------------------------------------------------------
    If (Not OnChangingPageGeneral(ps, PageName)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Node
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNode(ps, PageName)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Signal
    '-------------------------------------------------------------------------
    If (Not OnChangingPageSignal(ps, PageName)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Frame
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFrame(ps, PageName)) Then Exit Function
    '-------------------------------------------------------------------------
    'page: Schedule
    '-------------------------------------------------------------------------
    If (Not OnChangingPageSchedule(ps, PageName)) Then Exit Function
    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes(ps, PageName, sVarPre)) Then Exit Function

    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is an empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As peripherals, Controlname As String, v() As Variant, Page As Integer, PageName As String) As Boolean
    On Error GoTo OnShowError
    Dim sVarPre As String
    sVarPre = "LIN"

    OnShow = False

    '-------------------------------------------------------------------------
    ' page: General
    '-------------------------------------------------------------------------
    If (Not OnShowPageGeneral(ps, Controlname, PageName, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Node
    '-------------------------------------------------------------------------
    If (Not OnShowPageNode(ps, Controlname, PageName, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Signal
    '-------------------------------------------------------------------------
    If (Not OnShowPageSignal(ps, Controlname, PageName, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Frame
    '-------------------------------------------------------------------------
    If (Not OnShowPageFrame(ps, Controlname, PageName, v)) Then Exit Function
    '-------------------------------------------------------------------------
    ' page: Schedule
    '-------------------------------------------------------------------------
    If (Not OnShowPageSchedule(ps, Controlname, PageName, v)) Then Exit Function
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, PageName, sVarPre, v)) Then Exit Function


    
    OnShow = True
    Exit Function

OnShowError:
    errorbox "Can not show page.", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False

    Dim np As peripherals

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' buttons: General
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageGeneral(ps, Controlname)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' buttons: Node
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageNode(ps, Controlname)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' buttons: Signal
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageSignal(ps, Controlname)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' buttons: Frame
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageFrame(ps, Controlname)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' buttons: Schedule
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageSchedule(ps, Controlname)) Then Exit Function
    
    OnClick = True
    Exit Function

OnClickError:
    errorbox "Can not Text in OnClick.", Err.Description
    Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "LIN\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called on Termination.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'*****************************************************************************

Function OnTerminate(ps As peripherals)

'ObjectCollection.Add p, "LinFrames"
'ObjectCollection.Add s, "LinSignals"
'ObjectCollection.Add n, "LinNodes"
'ObjectCollection.Add st, "LinSchedules"

End Function


'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'General'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageGeneral(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageGeneral = False

  If (Not ps.AddPage("General")) Then Exit Function

  OnLoadPageGeneral = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageGeneral(ps As Object, PageName As String) As Boolean
  On Error Resume Next

  OnChangingPageGeneral = False
  
  If (Not ps.ExtenderCollection("General").Loaded) And (PageName = "General") Then
    ps.ExtenderCollection("General").Loaded = True
  

    '-------------------------------
    ' frame: frmLModes
    '-------------------------------
    If (Not ps.AddFrame("frmLModes", 120, 120, 4200, 1080, "Mode Selection")) Then Exit Function
        If (Not ps.AddOption("optLmaster", 200, 240, 1975, 380, "Master mode")) Then Exit Function
        If (Not ps.AddOption("optLslave", 200, 600, 1975, 380, "Slave mode")) Then Exit Function
        If (Not ps.AddLabel("lblLmaster", 0, 2235, 300, 1575, 385, "Master Name")) Then Exit Function
        If (Not ps.Addtext("txtLmaster", 2235, 600, 1800, 315)) Then Exit Function
        
    '-------------------------------
    ' frame: frmLldfile
    '-------------------------------
        If (Not ps.AddFrame("frmLMtr", 4440, 120, 4060, 1080, "Master Information")) Then Exit Function
        If (Not ps.AddLabel("lblLMtb", 0, 240, 240, 1575, 385, "Time Base (ms) ")) Then Exit Function
        If (Not ps.AddLabel("lblLMjtr", 0, 240, 600, 1575, 385, "Jitter (ms) ")) Then Exit Function
        If (Not ps.Addtext("txtLMtb", 1800, 240, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLMjtr", 1800, 600, 1800, 315)) Then Exit Function
        
    '-------------------------------
    ' frame: frmLldfile
    '-------------------------------
    If (Not ps.AddFrame("frmLldfile", 120, 1320, 4200, 1440, "LDF file")) Then Exit Function
        If (Not ps.AddOption("optLNoldf", 120, 240, 1275, 380, "No LDF")) Then Exit Function
        If (Not ps.AddOption("optLdave", 120, 600, 1275, 380, "Create LDF")) Then Exit Function
        If (Not ps.AddOption("optLuser", 120, 960, 1275, 380, "Select LDF")) Then Exit Function
        If (Not ps.AddLabel("lblLldf", 0, 1435, 660, 800, 385, "File Name")) Then Exit Function
        If (Not ps.Addtext("txtLldf", 2235, 600, 1800, 315)) Then Exit Function
        If (Not ps.AddButton("btnLldf", 2235, 1000, 1800, 315, "Browse")) Then Exit Function
    '-------------------------------
    ' frame: frmLldfCH
    '-------------------------------
    If (Not ps.AddFrame("frmLldfCH", 4440, 1320, 4060, 1440, "Source files")) Then Exit Function
        If (Not ps.AddLabel("lblLcfile", 0, 240, 240, 1575, 385, "C File")) Then Exit Function
        If (Not ps.AddLabel("lblLhfile", 0, 240, 600, 1575, 385, "Header File")) Then Exit Function
        If (Not ps.Addtext("txtLcfile", 1800, 240, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLhfile", 1800, 600, 1800, 315)) Then Exit Function

    '-------------------------------
    ' frame: frmLcfc
    '-------------------------------
    If (Not ps.AddFrame("frmLcfc", 120, 2880, 8380, 1800, "LIN Configuration")) Then Exit Function
        If (Not ps.AddLabel("lblLPver", 0, 120, 360, 1575, 385, "    Protocol Version")) Then Exit Function
        If (Not ps.AddLabel("lblLlang", 0, 120, 840, 1575, 385, "    Language")) Then Exit Function
        If (Not ps.AddLabel("lblLspeed", 0, 120, 1320, 1575, 385, "    Speed (kbps)")) Then Exit Function
        If (Not ps.AddCombo("cboLPver", 2235, 360, 1800, 315)) Then Exit Function
        If (Not ps.AddCombo("cboLlang", 2235, 840, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLspeed", 2235, 1320, 1800, 315)) Then Exit Function
        If (Not ps.AddLabel("lblLsupplier", 0, 4560, 360, 1575, 385, "Supplier ID")) Then Exit Function
        If (Not ps.AddLabel("lblLfunction", 0, 4560, 840, 1575, 385, "Function ID")) Then Exit Function
        If (Not ps.AddLabel("lblLvariant", 0, 4560, 1320, 1575, 385, "Variant ID")) Then Exit Function
        If (Not ps.Addtext("txtLsupplier", 6140, 340, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLfunction", 6140, 820, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLvariant", 6140, 1300, 1800, 315)) Then Exit Function
  End If
  OnChangingPageGeneral = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageGeneral(ps As Object, Controlname As String, PageName As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageGeneralError

  OnShowPageGeneral = False

  Dim r As Object
  Dim c As Object
  Dim e As Object
  Dim i As Integer
  
  Dim sVarPre   As String
  Dim Master As LinNode

  sVarPre = "LIN"
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (PageName = "General") Then
    '-------------------------------------------------------------------------
    ' page: General (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optLmaster (action)
        '---------------------------------------------------------------------
        Case "optLmaster"
             r.v("LIN_Mode") = 0
             c("txtLmaster").Enabled = True
             c("txtLMtb").Enabled = True
             c("txtLMjtr").Enabled = True
             c("txtLcfile").Enabled = True
             c("txtLhfile").Enabled = True
             c("txtLldf").Enabled = True
             c("optLdave").Enabled = True
             c("optLuser").Enabled = True
        '---------------------------------------------------------------------
        ' control: optLslave (action)
        '---------------------------------------------------------------------
        Case "optLslave"
             r.v("LIN_Mode") = 1
             c("txtLmaster").Enabled = False
             c("txtLMtb").Enabled = False
             c("txtLMjtr").Enabled = False
             c("txtLcfile").Enabled = False
             c("txtLhfile").Enabled = False
             c("txtLldf").Enabled = False
             c("optLdave").Enabled = False
             c("optLuser").Enabled = False

        '---------------------------------------------------------------------
        ' control: optLNoldf (action)
        '---------------------------------------------------------------------
        Case "optLNoldf"
             r.v("LIN_GEN_LDF") = 0
              r.v("LIN_USE_Init") = 0
        
        '---------------------------------------------------------------------
        ' control: optLdave (action)
        '---------------------------------------------------------------------
        Case "optLdave"
             r.v("LIN_GEN_LDF") = 1
             r.v("LIN_USE_Init") = 1
             UserMessage LIN_LDF_GENERATION
        '---------------------------------------------------------------------
        ' control: optLuser (action)
        '---------------------------------------------------------------------
        Case "optLuser"
            r.v("LIN_GEN_LDF") = 2
            r.v("LIN_USE_Init") = 1
        '---------------------------------------------------------------------
        ' control: txtLmaster (action)
        '---------------------------------------------------------------------
        Case "txtLmaster"
             If (n.Count) Then
                Set Master = n.item(1)
                r.v("LIN_M_Name") = v(1)
                Master.Name = r.v("LIN_M_Name")
             Else
                Set Master = New LinNode
                r.v("LIN_M_Name") = v(1)
                Master.Name = r.v("LIN_M_Name")
             End If
             
        '---------------------------------------------------------------------
        ' control: txtLMtb (action)
        '---------------------------------------------------------------------
        Case "txtLMtb"
             r.v("LIN_M_TBase") = v(1)
        '---------------------------------------------------------------------
        ' control: txtLMjtr (action)
        '---------------------------------------------------------------------
        Case "txtLMjtr"
             r.v("LIN_M_Jitter") = v(1)

        '---------------------------------------------------------------------
        ' control: txtLcfile (action)
        '---------------------------------------------------------------------
        Case "txtLcfile"
             r.v("LIN_CFile") = v(1)
        '---------------------------------------------------------------------
        ' control: txtLhfile (action)
        '---------------------------------------------------------------------
        Case "txtLhfile"
             r.v("LIN_HFile") = v(1)
             
        '---------------------------------------------------------------------
        ' control: txtLldf (action)
        '---------------------------------------------------------------------
        Case "txtLldf"
             r.v("LIN_LDF_File") = v(1)

        '---------------------------------------------------------------------
        ' control: cboLPver (action)
        '---------------------------------------------------------------------
        Case "cboLPver"
             r.v(sVarPre & "_protocol_version") = v(1)
        '---------------------------------------------------------------------
        ' control: txtLspeed (action)
        '---------------------------------------------------------------------
        Case "txtLspeed"
             If (IsInputFormatOk(v(1), "F", "LIN speed", 1, 20)) Then
                r.v("LIN_Speed") = v(1)
             End If
        '---------------------------------------------------------------------
        ' control: cboLlang (action)
        '---------------------------------------------------------------------
        Case "cboLlang"
             r.v(sVarPre & "_language_version") = v(1)
        '---------------------------------------------------------------------
        ' control: txtLsupplier (action)
        '---------------------------------------------------------------------
        Case "txtLsupplier"
            If (IsInputFormatOk(v(1), "H", "Supplier ID", 0, 32766)) Then
                r.v("LIN_supplier_id") = v(1)
            End If
        '---------------------------------------------------------------------
        ' control: txtLfunction (action)
        '---------------------------------------------------------------------
        Case "txtLfunction"
            If (IsInputFormatOk(v(1), "H", "Function ID", 0, 65534)) Then
               r.v("LIN_function_id") = v(1)
            End If
        '---------------------------------------------------------------------
        ' control: txtLvariant (action)
        '---------------------------------------------------------------------
        Case "txtLvariant"
            If (IsInputFormatOk(v(1), "D", "Variant ID", 0, 255)) Then
               r.v("LIN_variant_id") = v(1)
            End If
            
      Case Else
    End Select
    

    '-------------------------------------------------------------------------
    ' page: General (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optLmaster (show)
    '-------------------------------------------------------------------------
    With c("optLmaster")
      If (r.v("LIN_Mode") = 0) Then
            .Value = True
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optLslave (show)
    '-------------------------------------------------------------------------
    With c("optLslave")
      If (r.v("LIN_Mode") = 1) Then
            .Value = True
      End If
    End With
  
    '-------------------------------------------------------------------------
    ' control: optLNoldf (show)
    '-------------------------------------------------------------------------
    With c("optLNoldf")
      If (r.v("LIN_GEN_LDF") = 0) Then
            .Value = True
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optLdave (show)
    '-------------------------------------------------------------------------
    With c("optLdave")
      If (r.v("LIN_GEN_LDF") = 1) Then
            .Value = True
      End If
    End With
    With e("optLdave")
        .EnabledTooltipText = GEN_LDF
    End With

    '-------------------------------------------------------------------------
    ' control: optLuser (show)
    '-------------------------------------------------------------------------
    With c("optLuser")
      If (r.v("LIN_GEN_LDF") = 2) Then
            .Value = True
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: btnLldf (show)
    '-------------------------------------------------------------------------
    With c("btnLldf")
      If (r.v(sVarPre & "_GEN_LDF") = 2) And (r.v(sVarPre & "_Mode") = 0) Then
        .Enabled = True
      Else
        .Enabled = False
      End If
    End With
    With e("btnLldf")
        .EnabledTooltipText = GEN_LDFSEL
    End With

    '-------------------------------------------------------------------------
    ' control: lblLcfile (show)
    '-------------------------------------------------------------------------
    With c("lblLcfile")
    End With

    '-------------------------------------------------------------------------
    ' control: lblLhfile (show)
    '-------------------------------------------------------------------------
    With c("lblLhfile")
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtLmaster (show)
    '-------------------------------------------------------------------------
    With c("txtLmaster")
      .Text = r.v("LIN_M_Name")
    End With
    With e("txtLmaster")
        .EnabledTooltipText = GEN_MASTER
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtLMtb (show)
    '-------------------------------------------------------------------------
    With c("txtLMtb")
      .Text = r.v("LIN_M_TBase")
    End With
    With e("txtLMtb")
        .EnabledTooltipText = GEN_TB
    End With

    '-------------------------------------------------------------------------
    ' control: txtLMjtr (show)
    '-------------------------------------------------------------------------
    With c("txtLMjtr")
      .Text = r.v("LIN_M_Jitter")
    End With
    With e("txtLMjtr")
        .EnabledTooltipText = GEN_JT
    End With

    '-------------------------------------------------------------------------
    ' control: txtLcfile (show)
    '-------------------------------------------------------------------------
    With c("txtLcfile")
      .Enabled = False
      .Text = r.v("LIN_CFile")
    End With

    '-------------------------------------------------------------------------
    ' control: txtLhfile (show)
    '-------------------------------------------------------------------------
    With c("txtLhfile")
      .Enabled = False
      .Text = r.v("LIN_HFile")
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtLldf (show)
    '-------------------------------------------------------------------------
    With c("txtLldf")
      If (r.v(sVarPre & "_GEN_LDF") = 1 And (r.v(sVarPre & "_Mode") = 0)) Then
        .Enabled = True
        .Text = r.v(sVarPre & "_LDF_FILE")
      Else
        .Text = r.v("LIN_USR_LDF")
        .Enabled = False
      End If
    End With
    With e("txtLldf")
        .EnabledTooltipText = GEN_LDFNAME
    End With

    '-------------------------------------------------------------------------
    ' control: lblLPver (show)
    '-------------------------------------------------------------------------
    With c("lblLPver")
    End With

    '-------------------------------------------------------------------------
    ' control: lblLlang (show)
    '-------------------------------------------------------------------------
    With c("lblLlang")
    End With

    '-------------------------------------------------------------------------
    ' control: lblLspeed (show)
    '-------------------------------------------------------------------------
    With c("lblLspeed")
    End With

    '-------------------------------------------------------------------------
    ' control: cboLPver (show)
    '-------------------------------------------------------------------------
    With c("cboLPver")
      .Clear
      .AddItem ("2.0")
      For i = 0 To 2
        If (r.v(sVarPre & "_Protocol_Version") = c("cboLPver").List(i)) Then
            .listindex = i
        End If
      Next
    End With
    With e("cboLPver")
        .EnabledTooltipText = GEN_LINVER
    End With
 
    '-------------------------------------------------------------------------
    ' control: txtLspeed (show)
    '-------------------------------------------------------------------------
    With c("txtLspeed")
      .Text = r.v("LIN_Speed")
    End With
    With e("txtLspeed")
        .EnabledTooltipText = GEN_LINSPEED
    End With

    '-------------------------------------------------------------------------
    ' control: cboLlang (show)
    '-------------------------------------------------------------------------
    With c("cboLlang")
      .Clear
      .AddItem ("2.0")
      For i = 0 To 1
        If (r.v(sVarPre & "_Language_Version") = c("cboLlang").List(i)) Then
            .listindex = i
        End If
      Next
    End With
    With e("cboLlang")
        .EnabledTooltipText = GEN_LINLANG
    End With
    '-------------------------------------------------------------------------
    ' control: txtLsupplier (show)
    '-------------------------------------------------------------------------
    With c("txtLsupplier")
      .Text = FormatTextOutput(r.v("LIN_supplier_id"), "H4")
    End With
    With e("txtLsupplier")
        .EnabledTooltipText = GEN_SID
    End With
    '-------------------------------------------------------------------------
    ' control: txtLfunction (show)
    '-------------------------------------------------------------------------
    With c("txtLfunction")
      .Text = FormatTextOutput(r.v("LIN_function_id"), "H4")
    End With
    With e("txtLfunction")
        .EnabledTooltipText = GEN_FID
    End With
    '-------------------------------------------------------------------------
    ' control: txtLvariant (show)
    '-------------------------------------------------------------------------
    With c("txtLvariant")
      .Text = r.v("LIN_variant_id")
    End With
    With e("txtLvariant")
        .EnabledTooltipText = GEN_VID
    End With

  End If

  OnShowPageGeneral = True
  Exit Function

OnShowPageGeneralError:
errorbox "Error - " & PageName, Err.Description
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'General' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageGeneral(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageGeneralError

  OnButtonClickOnPageGeneral = False
  Dim f As String
  Dim r As ProjectData

  Set r = ps.ProjectData

  Select Case (Controlname)
    '---------------------------------------------------------------------
    ' control: btnLldf (action)
    '---------------------------------------------------------------------
    Case "btnLldf"
         'Open Browser to select the LDF file
         f = FileOpenExt("Select LDF File", "", "c:\", "*.*", "c:\", 5)
         r.v("LIN_USR_LDF") = f
    Case Else
  End Select

  OnButtonClickOnPageGeneral = True
  Exit Function

OnButtonClickOnPageGeneralError:
errorbox "Error - " & Controlname, Err.Description
  Exit Function
End Function




'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Node'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageNode(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageNode = False

  If (Not ps.AddPage("Node")) Then Exit Function

  OnLoadPageNode = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageNode(ps As Object, PageName As String) As Boolean
  On Error Resume Next

  OnChangingPageNode = False
  
  If (Not ps.ExtenderCollection("Node").Loaded) And (PageName = "Node") Then
    ps.ExtenderCollection("Node").Loaded = True
    Dim i As Integer
    '------------------------------
    ' frame: frmLncf
    '-------------------------------
    If (Not ps.AddFrame("frmLncf", 120, 120, 3840, 3480, "Slave Information")) Then Exit Function
        If (Not ps.AddLabel("lblLnode", 0, 120, 240, 1575, 395, "Node Name")) Then Exit Function
        If (Not ps.AddLabel("lblLrmrk", 0, 120, 860, 1575, 395, "Remark")) Then Exit Function
        If (Not ps.Addtext("txtLnode", 120, 500, 3600, 315)) Then Exit Function
        If (Not ps.Addtext("txtLrmrk", 120, 1120, 3600, 720)) Then Exit Function
        If (Not ps.AddOption("optLncfdave", 120, 2520, 1275, 240, "Create NCF")) Then Exit Function
        If (Not ps.Addtext("txtLncfdave", 1920, 2520, 1800, 315)) Then Exit Function
        If (Not ps.AddOption("optLncfusr", 120, 2880, 1275, 380, "Select NCF")) Then Exit Function
        If (Not ps.AddButton("btnLusrncf", 1920, 2900, 1800, 315, "Browse")) Then Exit Function
        If (Not ps.AddLabel("lblLncfh", 0, 120, 1900, 1575, 390, "NCF file")) Then Exit Function
        If (Not ps.AddOption("optLNOncf", 120, 2160, 1275, 240, "No NCF")) Then Exit Function

    '-------------------------------
    ' frame: frmLnslvs
    '-------------------------------
    If (Not ps.AddFrame("frmLnslvs", 4080, 120, 4500, 3480, "Slaves")) Then Exit Function
        If (Not ps.AddButton("btnLaddn", 2520, 2375, 1800, 315, "Add")) Then Exit Function
        If (Not ps.AddButton("btnLdeln", 2520, 2860, 1800, 315, "Delete")) Then Exit Function
        If (Not ps.Addlistbox("lstLnslvs", 120, 240, 2160, 3170)) Then Exit Function
        
    '-------------------------------
    ' frame: frmLms
    '-------------------------------
    If (Not ps.AddFrame("frmLD", 120, 3700, 8460, 1600, "Diagnostic Information")) Then Exit Function
        If (Not ps.AddLabel("lblLnad", 0, 120, 360, 1575, 395, "Diagnostic Addresses")) Then Exit Function
        If (Not ps.AddLabel("lblLp2min", 0, 120, 760, 1575, 395, "P2 min")) Then Exit Function
        If (Not ps.AddLabel("lblLstmin", 0, 120, 1160, 1775, 395, "ST min")) Then Exit Function
        If (Not ps.AddLabel("lblLmmlen", 0, 4100, 1160, 1575, 395, "Max_Msg_Length")) Then Exit Function
        If (Not ps.AddCombo("cboLnad", 1920, 360, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLp2min", 1920, 760, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLstmin", 1920, 1160, 1800, 315)) Then Exit Function
        If (Not ps.Addtext("txtLmmlen", 5400, 1160, 1800, 315)) Then Exit Function
  End If
  OnChangingPageNode = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageNode(ps As Object, Controlname As String, PageName As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageNodeError

  OnShowPageNode = False

  Dim r As Object
  Dim c As Object
  Dim e As Object
  Dim i As Integer
  Dim h As Integer
  Dim NodIndex As Integer
  Dim sVarPre As String
  Dim uNode As LinNode
  Dim bDisabled As Boolean
  Dim tNode       As New LinNode
  Dim bFlag As Boolean
  
  sVarPre = "LIN"
  Set uNode = New LinNode
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  
  
  If (PageName = "Node") Then
    '-------------------------------------------------------------------------
    ' page: Node (action)
    '-------------------------------------------------------------------------
        If r.v("LIN_NodeList_EXIST") Then
           NodIndex = r.v("LIST_NODE_INDEX") + 2
           If (n.Count < NodIndex) Then
            NodIndex = r.v("LIST_NODE_INDEX") + 1
           End If
        End If
            
            
    Select Case (Controlname)
        
        '---------------------------------------------------------------------
        ' control: cboLnad (action)
        '---------------------------------------------------------------------
        Case "cboLnad"
             r.v("LIN_Node_NAD") = v(1)
             Set uNode = n.item(NodIndex)
             For i = 1 To n.Count
                Set tNode = n.item(i)
                bFlag = True
                If (tNode.NAD = r.v("LIN_Node_NAD") And (tNode.Name <> uNode.Name)) Then
                    bFlag = False
                    UserMessage " NAD " & r.v("LIN_Node_NAD") & " already selected for " & _
                    tNode.Name & ". Please select anyother NAD."
                    Exit For
                End If
             Next i
             If (bFlag) Then
                uNode.NAD = r.v(sVarPre & "_Node_NAD")
             End If
        '---------------------------------------------------------------------
        ' control: txtLp2min (action)
        '---------------------------------------------------------------------
        Case "txtLp2min"
             r.v("LIN_Node_p2min") = v(1)
             Set uNode = n.item(NodIndex)
             uNode.p2min = r.v(sVarPre & "_Node_p2min")
        '---------------------------------------------------------------------
        ' control: txtLstmin (action)
        '---------------------------------------------------------------------
        Case "txtLstmin"
             r.v("LIN_Node_stmin") = v(1)
             Set uNode = n.item(NodIndex)
             uNode.stmin = r.v(sVarPre & "_Node_stmin")
        '---------------------------------------------------------------------
        ' control: txtLmmlen (action)
        '---------------------------------------------------------------------
        Case "txtLmmlen"
             If (IsInputFormatOk(v(1), "F", "LIN Max Message Length", 1, 4095)) Then
             r.v("LIN_Node_MaxMsglen") = v(1)
             Set uNode = n.item(NodIndex)
             uNode.MaxMsglen = r.v(sVarPre & "_Node_MaxMsglen")
             End If
        '---------------------------------------------------------------------
        ' control: txtLnode (action)
        '---------------------------------------------------------------------
        Case "txtLnode"
             r.v(sVarPre & "_Node_Name") = v(1)
             Set uNode = n.item(NodIndex)
             If (Not CheckListNames(ps, "lstLnslvs", r.v(sVarPre & "_Node_Name"))) Then
                uNode.Name = r.v(sVarPre & "_Node_Name")
                uNode.NCFname = uNode.Name & ".ncf"
             Else
                UserMessage SAME_LIST_NAME
             End If
            
        '---------------------------------------------------------------------
        ' control: txtLrmrk (action)
        '---------------------------------------------------------------------
        Case "txtLrmrk"
             r.v(sVarPre & "_Node_Remark") = v(1)
             Set uNode = n.item(NodIndex)
             uNode.Remark = r.v(sVarPre & "_Node_Remark")
             
            
        '---------------------------------------------------------------------
        ' control: txtLncfdave (action)
        '---------------------------------------------------------------------
        Case "txtLncfdave"
             r.v(sVarPre & "_NCF_FILE") = v(1)
             Set uNode = n.item(NodIndex)
             uNode.NCFname = r.v(sVarPre & "_NCF_FILE")
        '---------------------------------------------------------------------
        ' control: optLNOncf (action)
        '---------------------------------------------------------------------
        Case "optLNOncf"
             r.v(sVarPre & "_GEN_NCF") = 0

        '---------------------------------------------------------------------
        ' control: optLncfdave (action)
        '---------------------------------------------------------------------
        Case "optLncfdave"
             r.v(sVarPre & "_GEN_NCF") = 1
             r.v("LIN_USE_Init") = 1

        '---------------------------------------------------------------------
        ' control: optLncfusr (action)
        '---------------------------------------------------------------------
        Case "optLncfusr"
             r.v(sVarPre & "_GEN_NCF") = 2
        
        '---------------------------------------------------------------------
        ' control: lstLnslvs (action)
        '---------------------------------------------------------------------
        Case "lstLnslvs"
             r.v("LIST_NODE_INDEX") = c("lstLnslvs").listindex
             NodIndex = r.v("LIST_NODE_INDEX") + 2
             If (n.Count < NodIndex) Then
                NodIndex = r.v("LIST_NODE_INDEX") + 1
             End If
             Set uNode = n.item(NodIndex)
             r.v("LIN_Node_Name") = uNode.Name
             r.v("LIN_Node_Remark") = uNode.Remark
             r.v("LIN_Node_NAD") = uNode.NAD
             r.v("LIN_Node_p2min") = uNode.p2min
             r.v("LIN_Node_stmin") = uNode.stmin
             r.v("LIN_Node_MaxMsglen") = uNode.MaxMsglen
             
      Case Else
    End Select
    
    '-------------------------------------------------------------------------
    ' control: lblLnad (show)
    '-------------------------------------------------------------------------
    With c("lblLnad")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLnad
    End With

    '-------------------------------------------------------------------------
    ' control: lblLp2min (show)
    '-------------------------------------------------------------------------
    With c("lblLp2min")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLp2min
    End With
    
    '-------------------------------------------------------------------------
    'control:cboLnad (Show)
    '-------------------------------------------------------------------------
	
    With c("cboLnad")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
       .Clear
       For i = 1 To 127
         .AddItem (i)
       Next
        If (r.v("LIN_NodeList_EXIST")) Then
            Set uNode = n.item(NodIndex)
            If (r.v("LIN_NodeList_EXIST")) Then
            .listindex = uNode.NAD - 1
            Else
            .listindex = r.v(sVarPre & "_Node_NAD") - 1
            End If
        End If
    End With
    With e("cboLnad")
        .EnabledTooltipText = NODE_NAD
    End With

    '-------------------------------------------------------------------------
    ' control: txtLp2min (show)
    '-------------------------------------------------------------------------
	
    With c("txtLp2min")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
      If (r.v("LIN_NodeList_EXIST")) Then
        Set uNode = n.item(NodIndex)
        .Text = uNode.p2min
      Else
        .Text = ""
      End If
    End With
    With e("txtLp2min")
        .EnabledTooltipText = NODE_P2MIN
    End With

    '-------------------------------------------------------------------------
    ' control: txtLstmin (show)
    '-------------------------------------------------------------------------
	
    With c("txtLstmin")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
      If (r.v("LIN_NodeList_EXIST")) Then
        Set uNode = n.item(NodIndex)
        .Text = uNode.stmin
      Else
        .Text = ""
      End If
    End With
    With e("txtLstmin")
        .EnabledTooltipText = NODE_STMIN
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtLmmlen (show)
    '-------------------------------------------------------------------------
	
    With c("txtLmmlen")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
     If (r.v("LIN_NodeList_EXIST")) Then
        Set uNode = n.item(NodIndex)
        .Text = uNode.MaxMsglen
      Else
        .Text = ""
      End If
    End With
    With e("txtLmmlen")
        .EnabledTooltipText = NODE_MML
    End With
    '-------------------------------------------------------------------------
    ' control: lblLnode (show)
    '-------------------------------------------------------------------------
    With c("lblLnode")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLnode
    End With

    '-------------------------------------------------------------------------
    ' control: lblLrmrk (show)
    '-------------------------------------------------------------------------
    With c("lblLrmrk")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLrmrk
    End With
    '-------------------------------------------------------------------------
    ' control: txtLnode (show)
    '-------------------------------------------------------------------------
	
    With c("txtLnode")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
      If (r.v("LIN_NodeList_EXIST")) Then
        Set uNode = n.item(NodIndex)
        .Text = uNode.Name
      Else
        .Text = ""
      End If
    End With
    With e("txtLnode")
        .EnabledTooltipText = NODE_NAME
    End With

    '-------------------------------------------------------------------------
    ' control: txtLrmrk (show)
    '-------------------------------------------------------------------------
	
    With c("txtLrmrk")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
      If (r.v("LIN_NodeList_EXIST")) Then
        Set uNode = n.item(NodIndex)
        .Text = uNode.Remark
      Else
        .Text = ""
      End If
    End With
    With e("txtLrmrk")
        .EnabledTooltipText = NODE_REMARK
    End With
    '-------------------------------------------------------------------------
    ' control: optLNOncf (show)
    '-------------------------------------------------------------------------
	
    With c("optLNOncf")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
      If (r.v(sVarPre & "_GEN_NCF") = 0) Then
            .Value = True
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optLncfdave (show)
    '-------------------------------------------------------------------------
    With c("optLncfdave")
'      bDisabled = (r.v("LIN_NodeList_EXIST"))
'      .Enabled = (bDisabled)
'
'      If (r.v(sVarPre & "_GEN_NCF") = 1) Then
'            .Value = True
'      End If
'    End With
'    With e("optLncfdave")
'        .EnabledTooltipText = NODE_NCF
        .Enabled = False
    End With

    '-------------------------------------------------------------------------
    ' control: optLncfusr (show)
    '-------------------------------------------------------------------------
    With c("optLncfusr")
'      bDisabled = (r.v("LIN_NodeList_EXIST"))
'      .Enabled = (bDisabled)
'
'      If (r.v(sVarPre & "_GEN_NCF") = 2) Then
'            .Value = True
'      End If
        .Enabled = False
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtLncfdave (show)
    '-------------------------------------------------------------------------
    With c("txtLncfdave")
'      If (r.v(sVarPre & "_GEN_NCF") = 1) Then
'        .Enabled = True
'        Set uNode = n.item(NodIndex)
'        .Text = uNode.NCFname
'      ElseIf (r.v(sVarPre & "_GEN_NCF") = 2) Then
'        .Text = ""
'        .Text = r.v("LIN_USR_NCF")
'        .Enabled = False
'      Else
'        .Text = ""
'        .Enabled = False
'      End If
        .Enabled = False
    End With
'    With e("txtLncfdave")
'        .EnabledTooltipText = NODE_NCFNAME
'    End With

    '-------------------------------------------------------------------------
    ' control: btnLusrncf (show)
    '-------------------------------------------------------------------------
	
    With c("btnLusrncf")
      bDisabled = (r.v("LIN_NodeList_EXIST"))
      .Enabled = (bDisabled)
      
      If (r.v(sVarPre & "_GEN_NCF") = 2) Then
        .Enabled = True
      Else
        .Enabled = False
      End If
     
    End With
    With e("btnLusrncf")
        .EnabledTooltipText = NODE_NCFSEL
    End With

    '-------------------------------------------------------------------------
    ' control: lblLncfh (show)
    '-------------------------------------------------------------------------
    With c("lblLncfh")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLncfh
    End With

    '-------------------------------------------------------------------------
    ' control: btnLaddn (show)
    '-------------------------------------------------------------------------
    With c("btnLaddn")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: btnLaddn
    End With
    With e("btnLaddn")
        .EnabledTooltipText = NODE_BTNADD
    End With

    '-------------------------------------------------------------------------
    ' control: btnLdeln (show)
    '-------------------------------------------------------------------------
    With c("btnLdeln")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: btnLdeln
      .Enabled = (r.v("LIN_NodeList_EXIST"))
	  
    End With

    '-------------------------------------------------------------------------
    ' control: lstLnslvs (show)
    '-------------------------------------------------------------------------
	
    With c("lstLnslvs")
     .Clear
      If (r.v("LIN_NodeList_EXIST")) Then
        For i = 2 To n.Count
            Set uNode = n.item(i)
            .AddItem (uNode.Name)
        Next

        If ((c("lstLnslvs").ListCount - 1) <= r.v("LIST_NODE_INDEX")) Then
            r.v("LIST_NODE_INDEX") = c("lstLnslvs").ListCount - 1
        End If
        .listindex = r.v("LIST_NODE_INDEX")
      End If
   End With
    
  End If

  OnShowPageNode = True
  Exit Function

OnShowPageNodeError:
errorbox "Error - " & PageName, Err.Description
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Node' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageNode(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageNodeError

  OnButtonClickOnPageNode = False
  Dim f As String
  Dim c As Object
  Dim r As ProjectData
  Dim uNode As LinNode
  Dim Master As LinNode
  Dim NodIndex As Integer
  Dim listindex As Integer
  Dim i As Integer
  
  Set c = ps.ControlCollection
  Set r = ps.ProjectData
  Set uNode = New LinNode
  Set Master = New LinNode

  Select Case (Controlname)
    '---------------------------------------------------------------------
    ' control: btnLusrncf (action)
    '---------------------------------------------------------------------
    Case "btnLusrncf"
         'Open a browser to select NCF file
         f = FileOpenExt("Select NCF File", "", "c:\Program Files\DAvE", "*.*", "c:\Program Files\DAvE", 5)
         r.v("LIN_USR_NCF") = f
    '---------------------------------------------------------------------
    ' control: btnLaddn (action)
    '---------------------------------------------------------------------
    Case "btnLaddn"
    
    ' Adding Master to DAvE collection
            If (r.v("Master_Mode") = 0) Then
                Master.Name = r.v("LIN_M_Name")
                n.Add Master
                r.v("Master_Mode") = 1
            End If
         
   ' Adding Slaves to DAvE collection
            'Set the index for new Node
            If (c("lstLnslvs").ListCount) Then
                  NodKey = GetIndex(ps, "lstLnslvs")
            Else
                  NodKey = 0
            End If
            NodIndex = NodKey + 1
            
            'Check for the Max No. of nodes
            If (n.Count < 16) Then
                With c("lstLnslvs")
                    .AddItem ("Slave" & NodIndex)
                    r.v("LIST_NODE_INDEX") = .ListCount - 1
                    .listindex = r.v("LIST_NODE_INDEX")
                End With
                uNode.Name = "Slave" & NodIndex
                uNode.NCFname = uNode.Name & ".ncf"
                uNode.NAD = 127 - NodKey
                uNode.p2min = 0
                uNode.stmin = 0
                uNode.MaxMsglen = 4095
                
                'Add the Node details to DAvE collection
                n.Add uNode
                If (r.v("LIN_NodeList_EXIST")) Then
                    ObjectCollection.Remove "LinNodes"
                End If
                'Adding Node Objects<DAvEcollection> to the Object collection
                ObjectCollection.Add n, "LinNodes"
            End If
              
            r.v("LIN_NodeList_EXIST") = 1
            c("btnLdeln").Enabled = True
			
            Set uNode = n.item(c("lstLnslvs").ListCount + 1)
                c("txtLnode").Text = uNode.Name
                c("txtLrmrk").Text = uNode.Remark
                c("cboLnad").listindex = CInt(uNode.NAD - 1)
                c("txtLp2min").Text = uNode.p2min
                c("txtLstmin").Text = uNode.stmin
                c("txtLmmlen").Text = uNode.MaxMsglen
                If (r.v("LIN_GEN_NCF") = 1) Then
                c("txtLncfdave").Text = uNode.NCFname
                End If
             
            'Enable the controls in the Node page
            Call EnableOrDisableControls(ps, "Nodes")
    '---------------------------------------------------------------------
    ' control: btnLdeln (action)
    '---------------------------------------------------------------------
    Case "btnLdeln"
       If (r.v("LIN_NodeList_EXIST")) Then
       'Deleting a Node
         'get the index of the selected item
         listindex = c("lstLnslvs").listindex
         NodIndex = listindex + 2
         
         'Remove the selected Node from the DAvEcollection
         n.Remove (NodIndex)
         c("lstLnslvs").RemoveItem (listindex)
         
         If (c("lstLnslvs").ListCount) Then
                NodKey = GetIndex(ps, "lstLnslvs")
         End If
         
         'Adjust the index for the list
         If (c("lstLnslvs").ListCount) Then
            If (Not (c("lstLnslvs").ListCount <= listindex)) Then
                c("lstLnslvs").listindex = r.v("LIST_NODE_INDEX")
            Else
                r.v("LIST_NODE_INDEX") = c("lstLnslvs").ListCount - 1
                c("lstLnslvs").listindex = r.v("LIST_NODE_INDEX")
            End If
            Set uNode = n.item(r.v("LIST_NODE_INDEX") + 2)
                c("txtLnode").Text = uNode.Name
                c("txtLrmrk").Text = uNode.Remark
                c("txtLp2min").Text = uNode.p2min
                c("txtLstmin").Text = uNode.stmin
                c("txtLmmlen").Text = uNode.MaxMsglen
                c("cboLnad").listindex = CInt(uNode.NAD - 1)
                If (r.v("LIN_GEN_NCF") = 1) Then
                c("txtLncfdave").Text = uNode.NCFname
                End If
         Else
            r.v("LIN_NodeList_EXIST") = 0
            r.v("LIST_NODE_INDEX") = 0
            ObjectCollection.Remove "LinNodes"
            
                c("txtLnode").Text = ""
                c("txtLrmrk").Text = ""
                c("cboLnad").listindex = 126
                c("txtLp2min").Text = ""
                c("txtLstmin").Text = ""
                c("txtLmmlen").Text = ""
                c("txtLncfdave").Text = ""
                c("btnLdeln").Enabled = False
        End If
             
        'Disable the controls in the Node page
         Call EnableOrDisableControls(ps, "Nodes")
       Else
         MsgBox "There are no nodes in the cluster.", vbInformation
       End If
    Case Else
  End Select
    
  OnButtonClickOnPageNode = True
  Exit Function

OnButtonClickOnPageNodeError:
errorbox "Error - " & Controlname, Err.Description
  Exit Function
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Signal'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageSignal(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageSignal = False

  If (Not ps.AddPage("Signal")) Then Exit Function

  OnLoadPageSignal = True
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageSignal(ps As Object, PageName As String) As Boolean
  On Error Resume Next

  OnChangingPageSignal = False
  Dim i As Integer
  
  If (Not ps.ExtenderCollection("Signal").Loaded) And (PageName = "Signal") Then
    ps.ExtenderCollection("Signal").Loaded = True
    '-------------------------------
    ' frame: frmSigList
    '-------------------------------
    If (Not ps.AddFrame("frmSigList", 5160, 120, 3480, 5200, "Signal List")) Then Exit Function
        If (Not ps.AddButton("btnLsiglsta", 120, 4440, 960, 315, "Add")) Then Exit Function
        If (Not ps.Addlistbox("lstLssiglst", 120, 240, 3240, 3960)) Then Exit Function
        If (Not ps.AddButton("btnLsiglstd", 2400, 4440, 960, 315, "Delete")) Then Exit Function
    
    '-------------------------------
    ' frame: frmLssiginfo
    '-------------------------------
    If (Not ps.AddFrame("frmLssiginfo", 120, 120, 4920, 1300, "Signal Information")) Then Exit Function
        
        If (Not ps.AddLabel("lblLssigname", 0, 120, 240, 600, 255, "Name")) Then Exit Function
        If (Not ps.Addtext("txtLssigname", 820, 240, 1820, 360)) Then Exit Function
        If (Not ps.AddLabel("lblLssigtype", 0, 3080, 240, 1400, 255, "Signal Type")) Then Exit Function
        If (Not ps.AddOption("optLssigS", 3100, 440, 1575, 380, "Scalar")) Then Exit Function
        If (Not ps.AddOption("optLssigBA", 3100, 800, 1575, 380, "Byte Array")) Then Exit Function
        If (Not ps.AddLabel("lblLssigsize", 0, 120, 800, 600, 255, "Size (bit)")) Then Exit Function
        If (Not ps.AddCombo("cboLssigsize", 820, 800, 1820, 360)) Then Exit Function
        
    '-------------------------------
    ' frame: frmLsval
    '-------------------------------
    If (Not ps.AddFrame("frmLsval", 120, 1440, 4920, 1560, "Init Value")) Then Exit Function
        If (Not ps.AddOption("optLsvalint", 120, 240, 1575, 380, "Integer")) Then Exit Function
        If (Not ps.Addtext("txtLsint", 1520, 300, 1400, 360)) Then Exit Function
        If (Not ps.AddLabel("lblLssigOff", 0, 3080, 320, 600, 255, "Offset")) Then Exit Function
        If (Not ps.Addtext("txtLssigOff", 3560, 300, 1120, 360)) Then Exit Function
        If (Not ps.AddOption("optLsvalen", 120, 720, 1575, 380, "Encoding")) Then Exit Function
        If (Not ps.AddCombo("cboLsvalen1", 1520, 720, 3160, 315)) Then Exit Function
        If (Not ps.AddCombo("cboLsvalen2", 1520, 1080, 1815, 315)) Then Exit Function
        If (Not ps.Addlistbox("lstLsval", 3560, 1080, 1120, 380)) Then Exit Function

    '-------------------------------
    ' frame: frmLsignl
    '-------------------------------
    If (Not ps.AddFrame("frmLsignl", 120, 3000, 4920, 2330, "Signal")) Then Exit Function
        If (Not ps.AddLabel("lblLspub", 0, 120, 240, 720, 245, "Publisher")) Then Exit Function
        If (Not ps.AddLabel("lblLssub", 0, 2160, 240, 1080, 245, "Subscribers")) Then Exit Function
        If (Not ps.AddCombo("cboLspub", 120, 480, 1815, 315)) Then Exit Function
        If (Not ps.Addlistbox("lstLssub", 2160, 480, 900, 1800)) Then Exit Function
        For i = 0 To 7
            If (Not ps.AddCheck("chk" & i, 3160, 470 + (200 * i), 240, 240, "")) Then Exit Function
        Next
        If (Not ps.Addlistbox("lstLssub1", 3600, 480, 900, 1800)) Then Exit Function
        For i = 8 To 15
            If (Not ps.AddCheck("chk" & i, 4600, 470 + (200 * (i - 8)), 240, 240, "")) Then Exit Function
        Next

  End If
  OnChangingPageSignal = True
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageSignal(ps As Object, Controlname As String, PageName As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageSignalError

  OnShowPageSignal = False

  Dim r              As Object
  Dim c              As Object
  Dim e              As Object
  Dim i              As Integer
  Dim subcount       As Integer
  Dim sigIndex       As Integer
  Dim pubindex       As Integer
  Dim IndexPublisher As Integer
  Dim iInitCount     As Integer
  Dim iOldCount      As Integer
  Dim iOldSize       As Integer
  Dim subindex       As Integer
  Dim test           As Integer
  Dim vInitValArr    As Variant
  Dim sVarPre        As String
  Dim sOldSubName    As String
  Dim PublisherGet   As String
  Dim sInitValue     As String
  Dim sInitStr       As String
  Dim bDisabled      As Boolean
  Dim bRangeExceeded As Boolean
  
  Dim uSignal        As New LinSignal
  Dim uNode          As New LinNode
  Dim uFrame         As New LinFrame
  
  sVarPre = "LIN"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (PageName = "Signal") Then
    '-------------------------------------------------------------------------
    ' page: Signal (action)
    '-------------------------------------------------------------------------
        If r.v("LIN_SignalList_EXIST") Then
            r.v("LIST_SIGNAL_INDEX") = c("lstLssiglst").listindex
            If ((c("lstLssiglst").ListCount - 1) <= r.v("LIST_SIGNAL_INDEX")) Then
                r.v("LIST_SIGNAL_INDEX") = c("lstLssiglst").ListCount - 1
            End If
            sigIndex = r.v("LIST_SIGNAL_INDEX") + 1
            pubindex = r.v("LIST_SIGNAL_Pub")
        End If
        
    Select Case (Controlname)
    
        '---------------------------------------------------------------------
        ' control: lstLssiglst (action)
        '---------------------------------------------------------------------
        Case "lstLssiglst"
             r.v("LIST_SIGNAL_INDEX") = c("lstLssiglst").listindex
             sigIndex = r.v("LIST_SIGNAL_INDEX") + 1
             If (r.v("LIN_SignalList_EXIST")) Then
                Set uSignal = s.item(sigIndex)
             End If
        '---------------------------------------------------------------------
        ' control: cboLssigsize (action)
        '---------------------------------------------------------------------
        Case "cboLssigsize"
             r.v(sVarPre & "_Signal_Size") = v(1)
             If (r.v("LIN_SignalList_EXIST")) Then
                Set uSignal = s.item(sigIndex)
                iOldSize = uSignal.Size
                If (uSignal.SignalType) Then
                uSignal.Size = r.v(sVarPre & "_Signal_Size")
                    iInitCount = uSignal.Size \ 8
                    If (iOldSize < uSignal.Size) Then
                        iOldCount = iOldSize \ 8
                        For i = iOldCount To iInitCount - 1
                            uSignal.InitVal(i) = 0
                        Next
                    End If
                Else
                  If (((uSignal.Offset Mod 8) + r.v(sVarPre & "_Signal_Size")) <= 16) Then
                    uSignal.Size = r.v(sVarPre & "_Signal_Size")
                    If (uSignal.InitVal(0) > (2 ^ r.v(sVarPre & "_Signal_Size") - 1)) Then
                        uSignal.InitVal(0) = (2 ^ r.v(sVarPre & "_Signal_Size") - 1)
                    End If
                    If (uSignal.Offset > (64 - r.v(sVarPre & "_Signal_Size"))) Then
                        uSignal.Offset = 64 - r.v(sVarPre & "_Signal_Size")
                    End If
                  Else
                    UserMessage "The Signal Size and Offset selected will exceed 2 byte boundary."
                  End If
                End If
             End If
        '---------------------------------------------------------------------
        ' control: txtLssigname (action)
        '---------------------------------------------------------------------
        Case "txtLssigname"
            r.v(sVarPre & "_Signal_Name") = v(1)
            Set uSignal = s.item(sigIndex)
            sOldSubName = uSignal.Name

            For Each uNode In n
                For i = 0 To uNode.SSubCount - 1
                    If (uNode.SigSubscriber(i) = sOldSubName) Then
                        uNode.SigSubscriber(i) = r.v(sVarPre & "_Signal_Name")
                    End If
                Next i
                For i = 0 To uNode.SPubCount - 1
                    If (uNode.SigPublisher(i) = sOldSubName) Then
                        uNode.SigPublisher(i) = r.v(sVarPre & "_Signal_Name")
                    End If
                Next i
            Next
            For Each uFrame In p
                For i = 0 To uFrame.FrmSigCount - 1
                    If (uFrame.FrmSignals(i) = sOldSubName) Then
                        uFrame.FrmSignals(i) = r.v(sVarPre & "_Signal_Name")
                        
                    End If
                Next i
            Next
            If (Not CheckListNames(ps, "lstLssiglst", r.v(sVarPre & "_Signal_Name"))) Then
               uSignal.Name = r.v(sVarPre & "_Signal_Name")
            Else
               UserMessage SAME_LIST_NAME
            End If
            
        '---------------------------------------------------------------------
        ' control: optLsvalint (action)
        '---------------------------------------------------------------------
        Case "optLsvalint"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CLICKS ON THE OPTIONBUTTON: optLsvalint
             ' NOTE: v(1) CONTAINS THE VALUE

        '---------------------------------------------------------------------
        ' control: optLsvalen (action)
        '---------------------------------------------------------------------
        Case "optLsvalen"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CLICKS ON THE OPTIONBUTTON: optLsvalen
             ' NOTE: v(1) CONTAINS THE VALUE
             
        '---------------------------------------------------------------------
        ' control: optLssigS (action)
        '---------------------------------------------------------------------
        Case "optLssigS"
             r.v(sVarPre & "_Signal_Type") = 0
             If (r.v("LIN_SignalList_EXIST")) Then
                Set uSignal = s.item(sigIndex)
                uSignal.SignalType = r.v(sVarPre & "_Signal_Type")
                uSignal.Size = 1
                uSignal.InitVal(0) = 0
             End If

        '---------------------------------------------------------------------
        ' control: optLssigBA (action)
        '---------------------------------------------------------------------
        Case "optLssigBA"
             r.v(sVarPre & "_Signal_Type") = 1
             If (r.v("LIN_SignalList_EXIST")) Then
                Set uSignal = s.item(sigIndex)
                uSignal.SignalType = r.v(sVarPre & "_Signal_Type")
                uSignal.Size = 8
                uSignal.InitVal(0) = 0
             End If

        '---------------------------------------------------------------------
        ' control: txtLsint (action)
        '---------------------------------------------------------------------
        Case "txtLsint"
             If (r.v("LIN_SignalList_EXIST")) Then
                Set uSignal = s.item(sigIndex)
             End If
             If (uSignal.SignalType = 1) Then
                If (Not IsNumeric(v(1))) Then
                    If (InStr(v(1), "{")) Then
                        If (InStr(v(1), "}")) Then
                            sInitStr = Left(v(1), Len(v(1)) - 1)
                            sInitStr = Right(sInitStr, Len(v(1)) - 1)
                            vInitValArr = SplitArray(sInitStr, ",")
                            For i = LBound(vInitValArr) To UBound(vInitValArr)
                                If vInitValArr(i) > 255 Then bRangeExceeded = True
                            Next
                            If Not bRangeExceeded Then
                                For i = LBound(vInitValArr) To UBound(vInitValArr)
                                    uSignal.InitVal(i) = vInitValArr(i)
                                Next
                            Else
                                UserMessage "Value should be less than 256"
                            End If
                        Else
                            UserMessage "Expression should end with " & INV_COMMA & CURLY_BRACE2 & INV_COMMA
                        End If
                    Else
                        UserMessage "Expression should start with " & INV_COMMA & CURLY_BRACE1 & INV_COMMA
                    End If
                Else
                    UserMessage "The initial value should be an array of values, enclosed within " & vbCrLf & CURLY_BRACES
                End If
             Else
                r.v(sVarPre & "_Signal_InitVal") = v(1)
                If (IsInputFormatOk(v(1), "H4", "Signal InitVal")) Then
                    If (IsInputValueOK(v(1), 0, (2 ^ r.v(sVarPre & "_Signal_Size") - 1))) Then
                        uSignal.InitVal(0) = r.v(sVarPre & "_Signal_InitVal")
                    End If
                End If
             End If
             
        '---------------------------------------------------------------------
        ' control: txtLssigOff (action)
        '---------------------------------------------------------------------
        Case "txtLssigOff"
              r.v(sVarPre & "_Signal_Offset") = v(1)
             If (r.v("LIN_SignalList_EXIST")) Then
                Set uSignal = s.item(sigIndex)
                If (uSignal.SignalType) Then
                    If (IsInputFormatOk(v(1), "H4", "Signal Offset")) Then
                        If (IsInputValueOK(v(1), 0, (64 - r.v(sVarPre & "_Signal_Size")))) Then
                            uSignal.Offset = r.v(sVarPre & "_Signal_Offset")
                        End If
                    End If
                Else
                    If (((r.v(sVarPre & "_Signal_Offset") Mod 8) + uSignal.Size) <= 16) Then
                        If (IsInputFormatOk(v(1), "H4", "Signal Offset")) Then
                            If (IsInputValueOK(v(1), 0, (64 - r.v(sVarPre & "_Signal_Size")))) Then
                                uSignal.Offset = r.v(sVarPre & "_Signal_Offset")
                            End If
                        End If
                    Else
                        UserMessage "The Signal Size and Offset selected will exceed 2 byte boundary."
                    End If
                End If
             End If
        '---------------------------------------------------------------------
        ' control: cboLsvalen1 (action)
        '---------------------------------------------------------------------
        Case "cboLsvalen1"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CHANGES THE COMBOBOX: cboLsvalen1
             ' NOTE: v(1) CONTAINS THE TEXT OF THE SELECTED ENTRY

        '---------------------------------------------------------------------
        ' control: cboLsvalen2 (action)
        '---------------------------------------------------------------------
        Case "cboLsvalen2"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CHANGES THE COMBOBOX: cboLsvalen2
             ' NOTE: v(1) CONTAINS THE TEXT OF THE SELECTED ENTRY

        '---------------------------------------------------------------------
        ' control: lstLsval (action)
        '---------------------------------------------------------------------
        Case "lstLsval"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CLICKS ON THE LISTBOX: lstLsval
             ' NOTE: v(1) CONTAINS THE TEXT OF THE SELECTED ENTRY

        '---------------------------------------------------------------------
        ' control: cboLspub (action)
        '---------------------------------------------------------------------
        Case "cboLspub"
             r.v("LIN_Signal_Pub") = v(1)
            
             For i = 0 To (n.Count - 1)
                If (v(1) = c("cboLspub").List(i)) Then
                    pubindex = i
                End If
             Next
             r.v("LIST_SIGNAL_Pub") = pubindex
             If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, v(1), pubindex, sigIndex, "P"
             End If

        '---------------------------------------------------------------------
        ' control: lstLssub (action)
        '---------------------------------------------------------------------
        Case "lstLssub"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CLICKS ON THE LISTBOX: lstLssub
             ' NOTE: v(1) CONTAINS THE TEXT OF THE SELECTED ENTRY

        '---------------------------------------------------------------------
        ' control: lstLssub1 (action)
        '---------------------------------------------------------------------
        Case "lstLssub1"
             ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
             ' IF THE USER CLICKS ON THE LISTBOX: lstLssub1
             ' NOTE: v(1) CONTAINS THE TEXT OF THE SELECTED ENTRY
             

        '---------------------------------------------------------------------
        ' control: chk0 (action)
        '---------------------------------------------------------------------
        
        Case "chk0"
              If (r.v("LIN_SignalList_EXIST")) Then
              SetSignal ps, "chk0", 1, sigIndex, "S"
              End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk1"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk1", 2, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk2 (action)
        '---------------------------------------------------------------------
        Case "chk2"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk2", 3, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk3 (action)
        '---------------------------------------------------------------------
        Case "chk3"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk3", 4, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk4 (action)
        '---------------------------------------------------------------------
        Case "chk4"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk4", 5, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk5 (action)
        '---------------------------------------------------------------------
        Case "chk5"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk5", 6, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk6 (action)
        '---------------------------------------------------------------------
        Case "chk6"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk6", 7, sigIndex, "S"
                End If
               
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk7"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk7", 8, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk8"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk8", 9, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk9"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk9", 10, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk10"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk10", 11, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk11"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk11", 12, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk12"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk12", 13, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk13"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk13", 14, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk14"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk14", 15, sigIndex, "S"
                End If
        '---------------------------------------------------------------------
        ' control: chk1 (action)
        '---------------------------------------------------------------------
        Case "chk15"
                If (r.v("LIN_SignalList_EXIST")) Then
                SetSignal ps, "chk15", 16, sigIndex, "S"
                End If
        Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Signal (show)
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' control: chk (show)
    '-------------------------------------------------------------------------
  
    For i = n.Count To 15
        c("chk" & i).Enabled = False
    Next

    '-------------------------------------------------------------------------
    ' control: lstLssiglst (show)
    '-------------------------------------------------------------------------
    With c("lstLssiglst")
      .Clear
      If (r.v("LIN_SignalList_EXIST")) Then
            For i = 1 To s.Count
                Set uSignal = s.item(i)
                .AddItem (uSignal.Name)
            Next

            If ((c("lstLssiglst").ListCount - 1) <= r.v("LIST_SIGNAL_INDEX")) Then
                r.v("LIST_SIGNAL_INDEX") = c("lstLssiglst").ListCount - 1
            End If
            .listindex = r.v("LIST_SIGNAL_INDEX")

       End If
   End With

    '-------------------------------------------------------------------------
    ' control: btnLsiglsta (show)
    '-------------------------------------------------------------------------
    With c("btnLsiglsta")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: btnLsiglsta
      .Enabled = (r.v("LIN_NodeList_EXIST"))
    End With
    With e("btnLsiglsta")
        .EnabledTooltipText = SIGNAL_BTNADD
    End With
    
    '-------------------------------------------------------------------------
    ' control: btnLsiglstd (show)
    '-------------------------------------------------------------------------
    With c("btnLsiglstd")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: btnLsiglstd
      .Enabled = (r.v("LIN_SignalList_EXIST"))
    End With

    '-------------------------------------------------------------------------
    ' control: cboLssigsize (show)
    '-------------------------------------------------------------------------
    
    With c("cboLssigsize")
       .Enabled = (r.v("LIN_SignalList_EXIST"))
       If (r.v("LIN_SignalList_EXIST")) Then
           Set uSignal = s.item(sigIndex)
           'Signal type scalar value<1-16bits> 0r Byte array<1-8 bytes>
           If (uSignal.SignalType = 0) Then
                'Scalar Values
                .Clear
                For i = 1 To 16
                  .AddItem (i)
                Next
                c("optLssigS").Value = True
                c("optLssigBA").Value = False
                .listindex = 0
           Else
                'Byte Array
                .Clear
                For i = 8 To 64 Step 8
                  .AddItem (i)
                Next
                c("optLssigS").Value = False
                c("optLssigBA").Value = True
                .listindex = 0
           End If
          
           If (uSignal.SignalType = 0) Then
                For i = 0 To 15
                    If (uSignal.Size) = c("cboLssigsize").List(i) Then
                        .listindex = i
                    End If
                Next
            Else
                For i = 0 To 7
                    If (uSignal.Size) = c("cboLssigsize").List(i) Then
                        .listindex = i
                    End If
                Next
           End If
       Else
            .Clear
            For i = 1 To 16
              .AddItem (i)
            Next
       End If
     End With
    With e("cboLssigsize")
        .EnabledTooltipText = SIGNAL_SIZE
    End With
  
    '-------------------------------------------------------------------------
    ' control: lblLssigname (show)
    '-------------------------------------------------------------------------
    With c("lblLssigname")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLssigname
    End With

    '-------------------------------------------------------------------------
    ' control: lblLssigsize (show)
    '-------------------------------------------------------------------------
    With c("lblLssigsize")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLssigsize
    End With

    '-------------------------------------------------------------------------
    ' control: txtLssigname (show)
    '-------------------------------------------------------------------------
    
    With c("txtLssigname")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      If (r.v("LIN_SignalList_EXIST")) Then
        Set uSignal = s.item(sigIndex)
        .Text = uSignal.Name
      Else
        .Text = ""
      End If
      With e("txtLssigname")
          .EnabledTooltipText = SIGNAL_NAME
      End With
        
   End With

    '-------------------------------------------------------------------------
    ' control: optLsvalint (show)
    '-------------------------------------------------------------------------
    With c("optLsvalint")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      .Value = True
    End With

    '-------------------------------------------------------------------------
    ' control: optLsvalen (show)
    '-------------------------------------------------------------------------
    With c("optLsvalen")
       .Enabled = False
    End With

    '---------------------------------------------------------------------
    ' control: optLssigS (show)
    '---------------------------------------------------------------------
    With c("optLssigS")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      If (r.v("LIN_SignalList_EXIST")) Then
            Set uSignal = s.item(sigIndex)
            If (uSignal.SignalType = 0) Then
                .Value = True
                c("optLssigBA").Value = False
            End If
      Else
            .Value = True 'r.v("LIN_Signal_Type")
      End If
      
      End With
    With e("optLssigS")
        .EnabledTooltipText = SIGNAL_SCALAR
    End With

    '---------------------------------------------------------------------
    ' control: optLssigBA (show)
    '---------------------------------------------------------------------
    With c("optLssigBA")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      If (r.v("LIN_SignalList_EXIST")) Then
            Set uSignal = s.item(sigIndex)
            If (uSignal.SignalType = 1) Then
                .Value = True
                c("optLssigS").Value = False
            End If
      Else
            .Value = False
      End If
        
   End With
    With e("optLssigBA")
        .EnabledTooltipText = SIGNAL_BYTEARRAY
    End With
    '-------------------------------------------------------------------------
    ' control: txtLsint (show)
    '-------------------------------------------------------------------------
    With c("txtLsint")
      bDisabled = (Not (r.v("LIN_SignalList_EXIST")) = 1)
      .Enabled = Not bDisabled
      If (r.v("LIN_SignalList_EXIST")) Then
        Set uSignal = s.item(sigIndex)
        If (uSignal.SignalType) Then
            iInitCount = uSignal.Size / 8
            For i = 0 To iInitCount - 1
                sInitValue = sInitValue & "," & CStr(uSignal.InitVal(i))
            Next i
            sInitValue = "{" & Right(sInitValue, Len(sInitValue) - 1) & "}"
        Else
            sInitValue = CStr(uSignal.InitVal(0))
        End If
        .Text = sInitValue
      Else
        .Text = ""
      End If
    End With
    
    With e("txtLsint")
            .EnabledTooltipText = INITIAL_VALUE_TEMPLATE
    End With
    '-------------------------------------------------------------------------
    ' control: txtLssigOff (show)
    '-------------------------------------------------------------------------
    With c("txtLssigOff")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      If (r.v("LIN_SignalList_EXIST")) Then
        Set uSignal = s.item(sigIndex)
        .Text = uSignal.Offset
      Else
        .Text = ""
      End If
    End With
    With e("txtLssigOff")
        .EnabledTooltipText = SIGNAL_OFFSET
    End With

    '-------------------------------------------------------------------------
    ' control: cboLsvalen1 (show)
    '-------------------------------------------------------------------------
    With c("cboLsvalen1")
       .Enabled = False
      ' .ListIndex = r.v("TEST_VAR_INDEX")
    End With

    '-------------------------------------------------------------------------
    ' control: cboLsvalen2 (show)
    '-------------------------------------------------------------------------
    With c("cboLsvalen2")
       .Enabled = False
    End With

    '-------------------------------------------------------------------------
    ' control: lstLsval (show)
    '-------------------------------------------------------------------------
    With c("lstLsval")
       .Enabled = False
    End With

    '-------------------------------------------------------------------------
    ' control: lblLspub (show)
    '-------------------------------------------------------------------------
    With c("lblLspub")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLspub
    End With

    '-------------------------------------------------------------------------
    ' control: lblLssub (show)
    '-------------------------------------------------------------------------
    With c("lblLssub")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lblLssub
    End With

    '-------------------------------------------------------------------------
    ' control: cboLspub (show)
    '-------------------------------------------------------------------------

    With c("cboLspub")
      .Clear
    .Enabled = (r.v("LIN_SignalList_EXIST"))
       For i = 1 To n.Count
            Set uNode = n.item(i)
            .AddItem (uNode.Name)
            .listindex = 0
       Next

       If (r.v("LIN_SignalList_EXIST")) Then
           Set uSignal = s.item(sigIndex)
           PublisherGet = GetPublisherX(ps, "cboLspub", sigIndex, "Signal")
       End If
       For i = 0 To (n.Count - 1)
            If (PublisherGet = c("cboLspub").List(i)) Then
                .listindex = i
                IndexPublisher = i
            End If
       Next
     End With
    With e("cboLspub")
        .EnabledTooltipText = SIGNAL_PUBLISHER
    End With
     

    '-------------------------------------------------------------------------
    ' control: lstLssub (show)
    '-------------------------------------------------------------------------
    With c("lstLssub")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      .Clear
      
      If n.Count Then
      If (n.Count > 8) Then
            subcount = 8
      Else
            subcount = n.Count
      End If
      
      For i = 1 To subcount
          Set uNode = n.item(i)
          .AddItem (uNode.Name)
          c("chk" & (i - 1)).Enabled = True
      Next
      End If
    End With
    With e("lstLssub")
        .EnabledTooltipText = SIGNAL_SUBSCRIBERS
    End With

    '-------------------------------------------------------------------------
    ' control: lstLssub1 (show)
    '-------------------------------------------------------------------------
    With c("lstLssub1")
      .Enabled = (r.v("LIN_SignalList_EXIST"))
      .Clear
     If n.Count Then
       If (n.Count > 8) Then
            For i = 9 To n.Count
                Set uNode = n.item(i)
                .AddItem (uNode.Name)
                c("chk" & (i - 1)).Enabled = True
            Next
       End If
     End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: chk & x (show)
    '-------------------------------------------------------------------------
    
    If (r.v("LIN_SignalList_EXIST")) Then
        For i = 0 To 15
            With c("chk" & i)
              If (i < 8) Then
                test = GetSubscriberY(ps, c("lstLssub").List(i), sigIndex, "Signal")
              Else
                test = GetSubscriberY(ps, c("lstLssub1").List(i), sigIndex, "Signal")
              End If
        
              If (test = i + 1) Then
                .Value = 1
              Else
                .Value = 0
              End If
        
              If IndexPublisher = i Then
                .Value = 0
                .Enabled = False
              End If
            End With
        Next i
    Else
        For i = 0 To 15
            With c("chk" & i)
              .Value = 0
              .Enabled = False
            End With
        Next i
    End If
   
End If

  OnShowPageSignal = True
  Exit Function

OnShowPageSignalError:
errorbox "Error - " & PageName, Err.Description
Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Control         Name of the Signal Subscriber
'        Nindex          listindex of the Node in the list
'        sIndex          listindex of the Signal in the list
'        key             Shows Signal/Frame publisher node to be fetched
'*****************************************************************************

Public Sub SetSignal(ps As Object, Control As String, Nindex As Integer, sIndex As Integer, key As String)
On Error GoTo SetSignalError

  Dim c As Object
  Dim i As Integer
  Dim sc As Integer
  Dim pubindex As Integer
  Dim uSignal As LinSignal
  Dim uNode As LinNode
  Dim uFrame As New LinFrame
  Dim bFlag As Boolean
  
  Set c = ps.ControlCollection
  
  Set uNode = New LinNode
  Set uSignal = New LinSignal
  Set uSignal = s.item(sIndex)
  
  If (key = "S") Then                   'Set/reset Subscribers
    Set uNode = n.item(Nindex)
    If (c(Control).Value = 1) Then
        uNode.SigSubscriber(uNode.SSubCount) = uSignal.Name
        uNode.SSubCount = uNode.SSubCount + 1
        If iFrmAccount Then             'Set Frame Subscribers
        For Each uFrame In p
          If (uFrame.FrmSigCount) Then
            For i = 0 To (uFrame.FrmSigCount - 1)
            If uSignal.Name = uFrame.FrmSignals(i) Then
              uNode.FrmSubscriber(uNode.FSubCount) = uFrame.Name
              uNode.FSubCount = uNode.FSubCount + 1
            End If
            Next
          End If
        Next
        End If
    ElseIf (c(Control).Value = 0) Then
        If uNode.SSubCount Then         'Remove Signal Subscribers
        For sc = 0 To (uNode.SSubCount - 1)
          If uNode.SigSubscriber(sc) = uSignal.Name Then
             uNode.SigSubscriber(sc) = ""
          End If
        Next sc
        End If
        For Each uFrame In p            'Remove Frame Subscribers
          bFlag = False
          If (uFrame.FrmSigCount) Then
            For i = 0 To (uFrame.FrmSigCount - 1)
            If uSignal.Name = uFrame.FrmSignals(i) Then
            bFlag = True
            End If
            Next
          End If
          If bFlag Then
          If uNode.FSubCount Then
            For sc = 0 To (uNode.FSubCount - 1)
            If uNode.FrmSubscriber(sc) = uFrame.Name Then
               uNode.FrmSubscriber(sc) = ""
            End If
            Next sc
          End If
          End If
        Next
    End If
  ElseIf (key = "P") Then               'Set Publisher
    For i = 1 To n.Count
        Set uNode = n.item(i)
        If uNode.SPubCount Then
        For sc = 0 To (uNode.SPubCount - 1)
          If uSignal.Name = uNode.SigPublisher(sc) Then
          uNode.SigPublisher(sc) = ""
          End If
        Next sc
        End If
    Next i
        'Check for duplicates
         Set uNode = n.item(Nindex + 1)
         uNode.SigPublisher(uNode.SPubCount) = uSignal.Name
         uNode.SPubCount = uNode.SPubCount + 1
         'Remove the publisher from Subscribers List
         If uNode.SSubCount Then
         For sc = 0 To (uNode.SSubCount - 1)
          If uSignal.Name = uNode.SigSubscriber(sc) Then
          uNode.SigSubscriber(sc) = ""
          End If
         Next sc
         End If
  End If
  Exit Sub
SetSignalError:
  errorbox "ErrorSetSignal", Err.Description
 Exit Sub
End Sub

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Control         Name of the Signal Subscriber
'        sIndex          listindex of the Signal in the list
'        item            Shows Signal/Frame publisher node to be fetched
'-----------------------------------------------------------------------------
'Returns:
'        String          Name of Signal/Frame publisher Node in the
'                        LinNodes ObjectCollection
'*****************************************************************************

Public Function GetPublisherX(ps As Object, Control As String, sIndex As Integer, item As String) As String
On Error GoTo GetPublisherXError

  GetPublisherX = ""
  Dim i As Integer
  Dim pc As Integer
  Dim sc As Integer
  Dim pName As String
  Dim c As Object
  Dim uSignal As LinSignal
  Dim uNode As LinNode
  
  Set uSignal = New LinSignal
  Set uNode = New LinNode
  Set c = ps.ControlCollection
  Set uSignal = s.item(sIndex)

  For i = 1 To n.Count
    Set uNode = n.item(i)
    If (item = "Signal") Then       'Get Signal Publisher
       If uNode.SPubCount Then
       For pc = 0 To (uNode.SPubCount - 1)
        If (uSignal.Name = uNode.SigPublisher(pc)) Then
          pName = uNode.Name
        End If
       Next pc
       End If
    ElseIf (item = "Frame") Then    'Get Frame Publisher
       If uNode.FPubCount Then
       For pc = 0 To (uNode.FPubCount - 1)
        If (uSignal.Name = uNode.FrmPublisher(pc)) Then
          pName = uNode.Name
        End If
       Next pc
       End If
    End If
  Next i
  GetPublisherX = pName
  Exit Function
    
GetPublisherXError:
  errorbox "ErrorGetPublisher", Err.Description
  Exit Function
  End Function
    
'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Control         Name of the Signal Subscriber
'        sigIndex        lsitindex of the Signal in the list
'        item            Shows Signal/Frame subscriber to be fetched
'-----------------------------------------------------------------------------
'Returns:
'        String          Name of Signal/Frame subscriber Node in the
'                        LinNodes ObjectCollection
'*****************************************************************************

Public Function GetSubscriberX(ps As Object, Control As String, sIndex As Integer, item As String) As String
On Error GoTo GetSubscriberXError

  GetSubscriberX = ""
  Dim i As Integer
  Dim a As Integer
  Dim test As Integer
  Dim pc As Integer
  Dim sc As Integer
  Dim sName As String
  Dim c As Object
  Dim uSignal As LinSignal
  Dim uNode As LinNode
  
  Set uSignal = New LinSignal
  Set uNode = New LinNode
  Set c = ps.ControlCollection
  Set uSignal = s.item(sIndex)
 
  For i = 1 To n.Count
    Set uNode = n.item(i)
    If (item = "Signal") Then        'Get Signal Subscribers
      If uNode.SSubCount Then
        For pc = 0 To (uNode.SSubCount - 1)
        If (uSignal.Name = uNode.SigSubscriber(pc)) Then
          sName = uNode.Name
          For a = 0 To (c(Control).ListCount - 1)
             If (sName = c(Control).List(a)) Then
               sName = CStr(a)
             End If
          Next
          GetSubscriberX = sName
          Exit Function
        End If
        Next pc
      End If
    ElseIf (item = "Frame") Then     'Get Frame Subscribers
      If uNode.FSubCount Then
        For pc = 0 To (uNode.FSubCount - 1)
        If (uSignal.Name = uNode.FrmSubscriber(pc)) Then
          sName = uNode.Name
          GetSubscriberX = uNode.Name
          Exit Function
        End If
        Next pc
      End If
    End If
  Next i

GetSubscriberX = sName
Exit Function

GetSubscriberXError:
errorbox "ErrorGetSubscriber", Err.Description
Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        Signal page
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Control         Name of the Signal Subscriber
'        sigIndex        lsitindex of the Signal in the list
'        key             Shows Signal/Frame subscriber to be fetched
'-----------------------------------------------------------------------------
'Returns:
'        Integer         Index of Signal/Frame subscriber in the LinNodes
'*****************************************************************************

Public Function GetSubscriberY(ps As Object, Control As String, sIndex As Integer, key As String) As Integer
On Error GoTo GetSubscriberYError

  GetSubscriberY = 0
  Dim i As Integer
  Dim pc As Integer
  Dim sName As String
  Dim c As Object
  Dim uSignal As LinSignal
  Dim uNode As LinNode
  
  Set uSignal = New LinSignal
  Set uNode = New LinNode
  Set c = ps.ControlCollection
  Set uSignal = s.item(sIndex)

  For i = 1 To n.Count
    Set uNode = n.item(i)
    If (key = "Signal") Then            'Get Signal Subscribers
      If uNode.Name = Control Then
        If uNode.SSubCount Then
          For pc = 0 To (uNode.SSubCount - 1)
          If (uSignal.Name = uNode.SigSubscriber(pc)) Then
             GetSubscriberY = i
             Exit Function
          End If
          Next pc
        End If
      End If
    ElseIf (key = "Frame") Then         'Get Frame Subscribers
      If uNode.FSubCount Then
        For pc = 0 To (uNode.FSubCount - 1)
        If (uSignal.Name = uNode.FrmSubscriber(pc)) Then
          GetSubscriberY = i
          Exit Function
        End If
        Next pc
      End If
    End If
  Next i

  Exit Function

GetSubscriberYError:
errorbox "ErrorGetSubscriber", Err.Description
Exit Function
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Signal' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageSignal(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageSignalError

  OnButtonClickOnPageSignal = False
  
  Dim c         As Object
  Dim r         As Object
  Dim sigIndex  As Integer
  Dim listindex As Integer
  Dim i         As Integer
  Dim sVarPre   As String
  Dim PublisherGet   As String
  Dim IndexPublisher As Integer
  Dim uSignal   As LinSignal
  Dim uNode     As New LinNode
  
  sVarPre = "LIN"
  Set uSignal = New LinSignal
  
  Set c = ps.ControlCollection
  Set r = ps.ProjectData

  Select Case (Controlname)
    '---------------------------------------------------------------------
    ' control: btnLsiglsta (action)
    '---------------------------------------------------------------------
    Case "btnLsiglsta"
      If (r.v("LIN_NodeList_EXIST")) Then
         If (c("lstLssiglst").ListCount) Then
            SigKey = GetIndex(ps, "lstLssiglst")
         Else
            SigKey = 0
         End If
        
        'Add the Signal to the List
        sigIndex = SigKey + 1
        With c("lstLssiglst")
            .AddItem ("Signal" & sigIndex)
            r.v("LIST_SIGNAL_INDEX") = (c("lstLssiglst").ListCount - 1)
            .listindex = r.v("LIST_SIGNAL_INDEX")
        End With
                     
        'Assigning the object values
            uSignal.Name = "Signal" & sigIndex
            uSignal.ID = sigIndex
            uSignal.Offset = 0
            uSignal.SignalType = 0
            uSignal.InitVal(0) = 0
            uSignal.Size = 2
            
            If r.v("LIN_NodeList_EXIST") Then
                Set uNode = n.item(1)
            End If
            uNode.SigPublisher(uNode.SPubCount) = uSignal.Name
            uNode.SPubCount = uNode.SPubCount + 1
            ShowSignalSubscribers ps, IndexPublisher, 0  'Signal Subscribers
            
        'Add the Signal Details to DAvE Collection
            s.Add uSignal
            If (r.v("LIN_SignalList_EXIST")) Then
                ObjectCollection.Remove "LinSignals"
            End If
            'Adding Signal objects to Objects Collection
            ObjectCollection.Add s, "LinSignals"
            
        'Display the object
            r.v("LIN_SignalList_EXIST") = 1
            c("btnLsiglstd").Enabled = True
            Set uSignal = s.item(c("lstLssiglst").ListCount)
            c("txtLssigname").Text = uSignal.Name
            c("txtLsint").Text = uSignal.InitVal(0)
            c("txtLssigOff").Text = uSignal.Offset
            With c("cboLssigsize")                'Signal Size
            If (uSignal.SignalType = 0) Then
                .Clear
                For i = 1 To 16
                  .AddItem (i)
                Next
                c("optLssigS").Value = True
                c("optLssigBA").Value = False
                c("cboLssigsize").listindex = uSignal.Size - 1
            ElseIf (uSignal.SignalType = 1) Then
                .Clear
                For i = 8 To 64 Step 8
                  .AddItem (i)
                Next
                c("optLssigS").Value = False
                c("optLssigBA").Value = True
                c("cboLssigsize").listindex = (uSignal.Size / 8) - 1
            End If
            End With
            With c("cboLspub")                     'Signal Publisher
              .Clear
              .Enabled = (r.v("LIN_SignalList_EXIST"))
              For i = 1 To n.Count
                Set uNode = n.item(i)
                .AddItem (uNode.Name)
              Next
              sigIndex = c("lstLssiglst").ListCount
              PublisherGet = GetPublisherX(ps, "cboLspub", sigIndex, "Signal")
              For i = 0 To (n.Count - 1)
              If (PublisherGet = c("cboLspub").List(i)) Then
                .listindex = i
                IndexPublisher = i
              End If
              Next
            End With
            ShowSignalSubscribers ps, IndexPublisher, 1, sigIndex
            
            'Enable the controls in the Signal page
            Call EnableOrDisableControls(ps, "Signals")
      Else
          UserMessage "There are no nodes in the cluster."
      End If
    '---------------------------------------------------------------------
    ' control: btnLsiglstd (action)
    '---------------------------------------------------------------------
    Case "btnLsiglstd"
        If (r.v("LIN_SignalList_EXIST")) Then
        'Deleting the selected object from DAvEcollection
         listindex = c("lstLssiglst").listindex
         sigIndex = listindex + 1
         DeleteSignal ps, c("lstLssiglst").List(listindex) 'Delete from Subscribers & Publisher
         s.Remove (sigIndex)
         c("lstLssiglst").RemoveItem (listindex)
         If (c("lstLssiglst").ListCount) Then
            SigKey = GetIndex(ps, "lstLssiglst")
         End If
         
         'Adjust the Listindex of list
         If (c("lstLssiglst").ListCount) Then
            If (Not (c("lstLssiglst").ListCount <= listindex)) Then
                c("lstLssiglst").listindex = r.v("LIST_SIGNAL_INDEX")
            Else
                c("lstLssiglst").listindex = c("lstLssiglst").ListCount - 1
            End If
            'Display the object
             Set uSignal = s.item(c("lstLssiglst").ListCount)
                c("txtLssigname").Text = uSignal.Name
                c("txtLsint").Text = uSignal.InitVal(0)
                c("txtLssigOff").Text = uSignal.Offset
                With c("cboLssigsize")
                If (uSignal.SignalType = 0) Then
                    .Clear
                    For i = 1 To 16
                      .AddItem (i)
                    Next
                    c("optLssigS").Value = True
                    c("optLssigBA").Value = False
                    c("cboLssigsize").listindex = uSignal.Size - 1
                ElseIf (uSignal.SignalType = 1) Then
                    .Clear
                    For i = 8 To 64 Step 8
                      .AddItem (i)
                    Next
                    c("optLssigS").Value = False
                    c("optLssigBA").Value = True
                    c("cboLssigsize").listindex = (uSignal.Size / 8) - 1
                End If
                End With
                With c("cboLspub")                     'Signal Publisher
                  .Clear
                  .Enabled = (r.v("LIN_SignalList_EXIST"))
                  For i = 1 To n.Count
                    Set uNode = n.item(i)
                    .AddItem (uNode.Name)
                  Next
                  sigIndex = c("lstLssiglst").ListCount
                  PublisherGet = GetPublisherX(ps, "cboLspub", sigIndex, "Signal")
                  For i = 0 To (n.Count - 1)
                  If (PublisherGet = c("cboLspub").List(i)) Then
                    .listindex = i
                    IndexPublisher = i
                  End If
                  Next
                End With                                'Signal Subscribers
                ShowSignalSubscribers ps, IndexPublisher, 1, sigIndex
         Else
            r.v("LIN_SignalList_EXIST") = 0
            r.v("LIST_SIGNAL_INDEX") = 0
            ObjectCollection.Remove "LinSignals"
                c("txtLssigname").Text = ""
                c("txtLsint").Text = "0"
                c("txtLssigOff").Text = "0"
                c("cboLssigsize").Clear
                c("optLssigS").Value = True
                c("optLssigBA").Value = False
                c("btnLsiglstd").Enabled = False
                For i = 0 To 15
                c("chk" & i).Value = 0
                Next i
        End If
        
            'Disable the controls in the Signal page
            Call EnableOrDisableControls(ps, "Signals")
        Else
          UserMessage "There are no signals configured."
        End If
    Case Else
  End Select

  OnButtonClickOnPageSignal = True
  Exit Function

OnButtonClickOnPageSignalError:
errorbox "Error", Err.Description
  Exit Function
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Frame'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageFrame(ps As Object) As Boolean
  On Error GoTo OnLoadPageFrameError 'Resume Next

  OnLoadPageFrame = False

  If (Not ps.AddPage("Frame")) Then Exit Function
  If (bDiagFrm = False) Then
  If (Not DiagnosticFrames()) Then Exit Function
  End If
  iMaxFrm = 60
  
  OnLoadPageFrame = True
  Exit Function
OnLoadPageFrameError:
  errorbox "Error-OnLoadPageFrame", Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageFrame(ps As Object, PageName As String) As Boolean
  On Error GoTo OnChangingPageFrameError 'Resume Next

  OnChangingPageFrame = False
  Dim i As Integer
    
  If (Not ps.ExtenderCollection("Frame").Loaded) And (PageName = "Frame") Then
    ps.ExtenderCollection("Frame").Loaded = True

    '-------------------------------
    ' frame: frm_info
    '-------------------------------
    If (Not ps.AddFrame("frm_info", 120, 120, 4450, 4920, "Frame Information")) Then Exit Function
        If (Not ps.AddLabel("lbl_frm_name", 0, 120, 300, 1080, 365, "Name")) Then Exit Function
        If (Not ps.Addtext("txtFrameName", 1000, 240, 1200, 360)) Then Exit Function
        If (Not ps.AddLabel("lbl_frm_ID", 0, 2300, 300, 1080, 365, "Frame ID")) Then Exit Function
        If (Not ps.Addtext("txtID", 3150, 240, 1200, 360)) Then Exit Function
        If (Not ps.AddLabel("lbl_frm_msgid", 0, 120, 780, 1080, 365, "Message ID")) Then Exit Function
        If (Not ps.Addtext("txt_msgid", 1000, 680, 1200, 360)) Then Exit Function
        If (Not ps.AddLabel("lbl_frm_size", 0, 2300, 780, 1200, 365, "Size (Bytes)")) Then Exit Function
        If (Not ps.AddCombo("cbo_size", 3150, 680, 1200, 440)) Then Exit Function

        If (Not ps.AddLabel("lblFrmType", 0, 120, 1200, 1080, 365, "Frame Type")) Then Exit Function
        If (Not ps.AddCombo("cboFrmType", 1000, 1120, 1200, 440)) Then Exit Function
        If (Not ps.AddLabel("lblEvtSPRDid", 0, 2300, 1200, 1200, 365, "Frame IDs")) Then Exit Function
        If (Not ps.Addtext("txtEvtSPRDid", 3150, 1120, 1200, 360)) Then Exit Function
        If (Not ps.AddLabel("lblfrmft", 0, 120, 1570, 1800, 365, "Frame Transfer Time(ms)")) Then Exit Function
        If (Not ps.AddLabel("lblMinft", 0, 120, 1900, 1080, 365, "MinTime")) Then Exit Function
        If (Not ps.Addtext("txtMinft", 1000, 1850, 1200, 360)) Then Exit Function
        If (Not ps.AddLabel("lblMaxft", 0, 2300, 1900, 1080, 365, "MaxTime")) Then Exit Function
        If (Not ps.Addtext("txtMaxft", 3150, 1850, 1200, 360)) Then Exit Function

        If (Not ps.AddButton("btnFrmAdd", 3000, 3900, 1270, 315, "&Add")) Then Exit Function
        If (Not ps.AddLabel("lbl_frmlist", 0, 120, 2380, 1575, 250, "Frame List")) Then Exit Function
        If (Not ps.Addlistbox("lstFrmList", 120, 2640, 2500, 2160)) Then Exit Function
        If (Not ps.AddButton("btnFrmDel", 3000, 4300, 1270, 315, "&Delete")) Then Exit Function
    '-------------------------------
    ' frame: frmSignalData
    '-------------------------------
    If (Not ps.AddFrame("frmSignalData", 4670, 120, 3950, 4920, "Signal-Data mapping")) Then Exit Function
        If (Not ps.AddLabel("lbl_publish", 0, 120, 240, 1575, 365, "Published By")) Then Exit Function
        If (Not ps.AddCombo("cbo_publish", 1600, 240, 2150, 315)) Then Exit Function
        If (Not ps.AddLabel("lblSignal", 0, 120, 950, 1080, 365, "Signals")) Then Exit Function
        If (Not ps.Addlistbox("lstSignal", 120, 1200, 1350, 3450)) Then Exit Function
        If (Not ps.AddButton("btnSignalAdd", 1550, 2500, 800, 300, ">>")) Then Exit Function
        If (Not ps.AddLabel("lblData", 0, 2400, 950, 1800, 365, "Frame Signals")) Then Exit Function
        If (Not ps.Addlistbox("lstData", 2450, 1200, 1350, 3450)) Then Exit Function
        If (Not ps.AddButton("btnSignalDel", 1550, 3000, 800, 300, "<<")) Then Exit Function

  End If
  OnChangingPageFrame = True
  Exit Function
OnChangingPageFrameError:
    errorbox "Error-OnChange", Err.Description
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFrame(ps As Object, Controlname As String, PageName As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFrameError

  OnShowPageFrame = False

  Dim r         As Object
  Dim c         As Object
  Dim e         As Object
  Dim i         As Integer
  Dim j         As Integer
  Dim iold      As Integer
  Dim frmIndex  As Integer
  Dim sigIndex  As Integer
  Dim iDummy    As Integer
  Dim iRemainder As Integer
  Dim iMaxTime  As Integer
  Dim bDisabled As Boolean
  Dim bFlag     As Boolean
  Dim sEvtSPRDStr   As String
  Dim sEvtSPRDFrm   As String
  Dim sVarPre   As String
  Dim sFrmPub   As String
  Dim sPubNode  As String
  Dim sTmpFrame As String
  Dim tmpName   As String
  Dim tempArr   As Variant
  Dim iMsgID    As Long
  Dim iFrameID  As Integer
  
  Dim uFrame    As New LinFrame
  Dim uSignal   As New LinSignal
  Dim uNode     As New LinNode
  
  

  sVarPre = "LIN"
  sPubNode = "Master"
  
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  If (PageName = "Frame") Then
    '-------------------------------------------------------------------------
    ' page: Frame (action)
    '-------------------------------------------------------------------------
        If r.v("LIN_FrameList_EXIST") Then
            frmIndex = r.v("LIST_FRAME_INDEX") + 3
        End If
        
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: lstData (action)
        '---------------------------------------------------------------------
        Case "lstData"
             r.v("lstData_INDEX") = c("lstData").listindex

        '---------------------------------------------------------------------
        ' control: lstFrmList (action)
        '---------------------------------------------------------------------
        Case "lstFrmList"
            r.v("LIST_FRAME_INDEX") = c("lstFrmList").listindex
            frmIndex = r.v("LIST_FRAME_INDEX") + 3
            If (n.Count) Then
                Set uNode = n.item(r.v(sVarPre & "_PubIndex") + 1)
                If (uNode.SPubCount) Then
                   r.v(sVarPre & "_SigIndex") = 0
                End If
            End If
        '---------------------------------------------------------------------
        ' control: txtFrameName (action)
        '---------------------------------------------------------------------
        Case "txtFrameName"
            r.v(sVarPre & "_Frame_Name") = v(1)
            Set uFrame = p.item(frmIndex)
            sTmpFrame = uFrame.Name
            For Each uNode In n
               For i = 0 To uNode.FPubCount - 1
                   If (uNode.FrmPublisher(i) = sTmpFrame) Then
                       uNode.FrmPublisher(i) = r.v(sVarPre & "_Frame_Name")
                   End If
               Next
               
               For i = 0 To uNode.FSubCount - 1
                   If (uNode.FrmSubscriber(i) = sTmpFrame) Then
                       uNode.FrmSubscriber(i) = r.v(sVarPre & "_Frame_Name")
                   End If
               Next
            Next
            If (Not CheckListNames(ps, "lstFrmList", r.v(sVarPre & "_Frame_Name"))) Then
                uFrame.Name = r.v(sVarPre & "_Frame_Name")
            Else
                UserMessage SAME_LIST_NAME
            End If

        '---------------------------------------------------------------------
        ' control: txtID (action)
        '---------------------------------------------------------------------
        Case "txtID"
             Set uFrame = p.item(frmIndex)
             If (IsInputFormatOk(v(1), "H4", "Frame ID", 0, 59)) Then
                If (Not CheckForSameID(v(1))) Then
                    uFrame.ID = v(1)
                    If (v(1) < 32) Then
                        r.v(sVarPre & "_Frame_Length") = 2
                    ElseIf (v(1) < 48) Then
                        r.v(sVarPre & "_Frame_Length") = 4
                    Else
                        r.v(sVarPre & "_Frame_Length") = 8
                    End If
                    
                    iold = uFrame.Length
                    uFrame.Length = r.v(sVarPre & "_Frame_Length")
                    
                    If (iold < uFrame.Length) Then
                        For i = (iold * 8) To (uFrame.Length * 8) - 1
                        uFrame.FrmSignals(i) = ""
                        Next i
                    ElseIf (iold > uFrame.Length) Then
                        If (uFrame.FrmSignals((uFrame.Length * 8) - 1) <> "") Then
                        ResizeFrame uFrame.Name, uFrame.FrmSignals((uFrame.Length * 8) - 1)
                        End If
                    End If
                    
                Else
                    UserMessage SAME_FRAME_ID
                End If
             End If
             
             
        '---------------------------------------------------------------------
        ' control: txt_msgid (action)
        '---------------------------------------------------------------------
        Case "txt_msgid"
             Set uFrame = p.item(frmIndex)
             If (IsInputFormatOk(v(1), "H4", "Message ID", 0, 65534)) Then
                If (Not CheckForSameID(0, v(1))) Then
                    uFrame.MsgID = v(1)
                Else
                    UserMessage SAME_MESSAGE_ID
                End If
             End If
             
        '---------------------------------------------------------------------
        ' control: txtEvtSPRDid (action)
        '---------------------------------------------------------------------
        Case "txtEvtSPRDid"
            Set uFrame = p.item(frmIndex)
            tempArr = SplitArray(v(1), ",")
            For i = 0 To iArrayCount - 1
                uFrame.EvtSPRDFrm(i) = -1
                uFrame.EvtSPRDCount = 0
            Next
            
          If (CheckUNCDFrmPub(tempArr, iArrayCount)) Then
            
            For j = 0 To iArrayCount - 1
                For i = j To iArrayCount - 1
                    If (tempArr(i) = uFrame.EvtSPRDFrm(j)) Then
                        If (Not (i = j)) Then
                            tempArr(i) = -1
                            uFrame.EvtSPRDFrm(i) = -1
                            uFrame.EvtSPRDCount = uFrame.EvtSPRDCount + 1
                            UserMessage EVENT_Trig_FRAME_ERROR
                            bFlag = True
                            Exit For
                        End If
                    Else
                        If (i = j) Then
                            If (CheckEvtSPRDFrameID(uFrame.ID, tempArr(i))) Then
                                tempArr(i) = -1
                                uFrame.EvtSPRDFrm(j) = -1
                                uFrame.EvtSPRDCount = uFrame.EvtSPRDCount + 1
                                UserMessage EVENT_Trig_FRAME_ERROR
                            ElseIf (FrameIDExists(tempArr(i))) Then
                                If (CheckUNCDFrmID(tempArr(0), tempArr(i))) Then
                                uFrame.EvtSPRDFrm(j) = tempArr(i)
                                uFrame.EvtSPRDCount = uFrame.EvtSPRDCount + 1
                                End If
                            Else
                                UserMessage NON_EXISTENT_ID
                            End If
                        End If
                End If
                    Next i
                If (bFlag) Then
                    bFlag = False
                    Exit For
                End If
            Next j
          End If

        '---------------------------------------------------------------------
        ' control: txtMaxft (action)
        '---------------------------------------------------------------------
        Case "txtMaxft"
            r.v(sVarPre & "_Frame_MaxTime") = v(1)
            Set uFrame = p.item(frmIndex)
            If (IsNumeric(r.v(sVarPre & "_Frame_MaxTime"))) Then
                iMaxTime = CInt(r.v(sVarPre & "_Frame_MaxTime"))
                iRemainder = iMaxTime Mod r.v("LIN_M_TBase")
                If ((iRemainder = 0)) Then
                    If (r.v(sVarPre & "_Frame_MaxTime") >= uFrame.MinPeriod) Then
                        uFrame.MaxPeriod = r.v(sVarPre & "_Frame_MaxTime")
                    Else
                        UserMessage "MaxPeriod should always be greater than or equal to" _
                                 & " MinPeriod"
                    End If
                Else
                    UserMessage TIMEBASE_ERROR
                End If
            End If
             
        '---------------------------------------------------------------------
        ' control: txtMinft (action)
        '---------------------------------------------------------------------
        Case "txtMinft"
            r.v(sVarPre & "_Frame_MinTime") = v(1)
            Set uFrame = p.item(frmIndex)
            If (IsNumeric(r.v(sVarPre & "_Frame_MinTime"))) Then
                iMaxTime = CInt(r.v(sVarPre & "_Frame_MinTime"))
                iRemainder = iMaxTime Mod r.v("LIN_M_TBase")
                If ((iRemainder = 0)) Then
                    If (uFrame.MaxPeriod >= r.v(sVarPre & "_Frame_MinTime")) Then
                        uFrame.MinPeriod = r.v(sVarPre & "_Frame_MinTime")
                    Else
                        UserMessage "MinPeriod should always be lesser than or equal to" _
                                 & " MaxPeriod"
                    End If
                Else
                    UserMessage TIMEBASE_ERROR
                End If
            End If
            
        '---------------------------------------------------------------------
        ' control: cbo_size (action)
        '---------------------------------------------------------------------
        Case "cbo_size"
            r.v(sVarPre & "_Frame_Length") = v(1)
            Set uFrame = p.item(frmIndex)
            iold = uFrame.Length
            uFrame.Length = r.v(sVarPre & "_Frame_Length")
            If (iold < uFrame.Length) Then
                For i = (iold * 8) To (uFrame.Length * 8) - 1
                uFrame.FrmSignals(i) = ""
                Next
            ElseIf (iold > uFrame.Length) Then
                If (uFrame.FrmSignals((uFrame.Length * 8) - 1) <> "") Then
                ResizeFrame uFrame.Name, uFrame.FrmSignals((uFrame.Length * 8) - 1)
                End If
            End If
            
        '---------------------------------------------------------------------
        ' control: cboFrmType (action)
        '---------------------------------------------------------------------
        Case "cboFrmType"
            r.v(sVarPre & "_Frame_Type") = v(1)
            Set uFrame = p.item(frmIndex)
            uFrame.FrmType = v(1)

        '---------------------------------------------------------------------
        ' control: lstSignal (action)
        '---------------------------------------------------------------------
        Case "lstSignal"
            r.v(sVarPre & "_SigIndex") = c("lstSignal").listindex

        '---------------------------------------------------------------------
        ' control: cbo_publish (action)
        '---------------------------------------------------------------------
        Case "cbo_publish"
            r.v(sVarPre & "_PubIndex") = c("cbo_publish").listindex
            If (uNode.SPubCount) Then
                r.v(sVarPre & "_SigIndex") = 0
            End If
            Set uNode = n.item(r.v(sVarPre & "_PubIndex") + 1)
            Set uFrame = p.item(frmIndex)
            iDummy = frmIndex
            
            For i = 0 To uNode.FPubCount - 1            'Frame Publisher
                If (uNode.FrmPublisher(i) = uFrame.Name) Then
                    bFlag = True
                    Exit For
                Else
                    bFlag = False
                End If
            Next i
            If (Not bFlag) Then
                RemoveOldPublisher uFrame
                uNode.FrmPublisher(uNode.FPubCount) = uFrame.Name
                uNode.FPubCount = uNode.FPubCount + 1
            End If
            RemoveOldSubscriber uFrame, uNode          'Frame Subscriber
        
        Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Frame (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: lstData (show)
    '-------------------------------------------------------------------------
    
    With c("lstData")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        .Clear
        If (r.v("LIN_FrameList_EXIST")) Then
            Set uFrame = p.item(frmIndex)
        End If
  
        If (uFrame.FrmSigCount) Then
            For i = 0 To ((uFrame.Length * 8) - 1)
                If (uFrame.FrmSignals(i) <> "") Then
                    If (tmpName <> uFrame.FrmSignals(i)) Then
                        .AddItem (uFrame.FrmSignals(i))
                        tmpName = uFrame.FrmSignals(i)
                    End If
                End If
            Next
        
            If (c("lstData").ListCount <= r.v("lstData_INDEX")) Then
                r.v("lstData_INDEX") = c("lstData").ListCount - 1
            End If
            .listindex = r.v("lstData_INDEX")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lstFrmList (show)
    '-------------------------------------------------------------------------
    With c("lstFrmList")
        .Clear
        If (r.v("LIN_FrameList_EXIST")) Then
            For i = 3 To p.Count
                Set uFrame = p.item(i)
                .AddItem (uFrame.Name)
            Next
            .listindex = r.v("LIST_FRAME_INDEX")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: btn_frm_add (show)
    '-------------------------------------------------------------------------
    With c("btnFrmAdd")
       .Enabled = (r.v("LIN_SignalList_EXIST"))
    End With
    With e("btnFrmAdd")
        .EnabledTooltipText = FRAME_BTNADD
    End With

    '-------------------------------------------------------------------------
    ' control: btn_frm_del (show)
    '-------------------------------------------------------------------------
    With c("btnFrmDel")
       .Enabled = (r.v("LIN_FrameList_EXIST"))
    End With
    '-------------------------------------------------------------------------
    ' control: btnSignalAdd (show)
    '-------------------------------------------------------------------------
    With c("btnSignalAdd")
        If (c("cboFrmType").listindex <> 0) Then
        .Enabled = False
        End If
    End With
    With e("btnSignalAdd")
        .EnabledTooltipText = FRAME_BTNSIGe
        .DisabledTooltipText = FRAME_BTNSIGd
    End With

    '-------------------------------------------------------------------------
    ' control: btnSignalDel (show)
    '-------------------------------------------------------------------------
    With c("btnSignalDel")
        If (c("cboFrmType").listindex <> 0) Then
        .Enabled = False
        End If
    End With
    
    '-------------------------------------------------------------------------
    ' control: lbl_frmlist (show)
    '-------------------------------------------------------------------------
    With c("lbl_frmlist")
    
    End With

    '-------------------------------------------------------------------------
    ' control: txtFrameName (show)
    '-------------------------------------------------------------------------
    With c("txtFrameName")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        If r.v("LIN_FrameList_EXIST") Then
            Set uFrame = p.item(frmIndex)
            .Text = uFrame.Name
        Else
            .Text = ""
        End If
    End With
    With e("txtFrameName")
        .EnabledTooltipText = FRAME_NAME
    End With
   
    '-------------------------------------------------------------------------
    ' control: lbl_frm_name (show)
    '-------------------------------------------------------------------------
    With c("lbl_frm_name")
    
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_frm_ID (show)
    '-------------------------------------------------------------------------
    With c("lbl_frm_ID")
    
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtID (show)
    '-------------------------------------------------------------------------
    With c("txtID")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        If r.v("LIN_FrameList_EXIST") Then
            If (uFrame.FrmType <> "Sporadic") Then
                Set uFrame = p.item(frmIndex)
                .Text = uFrame.ID
            Else
                .Text = ""
            End If
        End If
    End With
    With e("txtID")
        .EnabledTooltipText = FRAME_ID
    End With
    
    '-------------------------------------------------------------------------
    ' control: txt_msgid (show)
    '-------------------------------------------------------------------------
    With c("txt_msgid")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        If r.v("LIN_FrameList_EXIST") Then
            If (uFrame.FrmType <> "Sporadic") Then
                Set uFrame = p.item(frmIndex)
                .Text = FormatTextOutput(uFrame.MsgID, "H4")
            Else
                .Text = ""
            End If
        End If
    End With
    With e("txt_msgid")
        .EnabledTooltipText = FRAME_MsgID
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtEvtSPRDid (show)
    '-------------------------------------------------------------------------
    With c("txtEvtSPRDid")

        If r.v("LIN_FrameList_EXIST") Then
            Set uFrame = p.item(frmIndex)
            bDisabled = (uFrame.FrmType = "Unconditional")
            .Enabled = Not bDisabled
            If (uFrame.EvtSPRDCount) Then
                sEvtSPRDStr = JoinArray(frmIndex, ",")
            End If
            If (Not bDisabled) Then
                .Text = sEvtSPRDStr
            Else
                .Text = ""
            End If
        Else
            bDisabled = True
            .Enabled = Not bDisabled
        End If
    End With
    With e("txtEvtSPRDid")
        .EnabledTooltipText = FRAME_EvtIDs
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtMaxft (show)
    '-------------------------------------------------------------------------
    With c("txtMaxft")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        If r.v("LIN_FrameList_EXIST") Then
            Set uFrame = p.item(frmIndex)
            .Text = uFrame.MaxPeriod
        Else
            .Text = ""
        End If
    End With
    With e("txtMaxft")
        .EnabledTooltipText = FRAME_MINMAX
    End With
    
    '-------------------------------------------------------------------------
    ' control: txtMinft (show)
    '-------------------------------------------------------------------------
    With c("txtMinft")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
       If r.v("LIN_FrameList_EXIST") Then
            Set uFrame = p.item(frmIndex)
            .Text = uFrame.MinPeriod
       Else
            .Text = ""
       End If
    End With
    With e("txtMinft")
        .EnabledTooltipText = FRAME_MINMAX
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_frm_size (show)
    '-------------------------------------------------------------------------
    With c("lbl_frm_size")
    
    End With

    '-------------------------------------------------------------------------
    ' control: cbo_size (show)
    '-------------------------------------------------------------------------
    With c("cbo_size")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        .Clear
        For i = 1 To 8
          .AddItem (i)
        Next
        If r.v("LIN_FrameList_EXIST") Then
            Set uFrame = p.item(frmIndex)
            .listindex = uFrame.Length - 1
        End If
     
    End With
    With e("cbo_size")
        .EnabledTooltipText = FRAME_SIZE
    End With
    '-------------------------------------------------------------------------
    ' control: cboFrmType (show)
    '-------------------------------------------------------------------------
    With c("cboFrmType")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        .Clear
        .AddItem ("Unconditional")
        .AddItem ("Event_Triggered")
        .AddItem ("Sporadic")
        
        If (r.v("LIN_FrameList_EXIST")) Then
              Set uFrame = p.item(frmIndex)
              For i = 0 To .ListCount - 1
                    If (uFrame.FrmType = .List(i)) Then
                        .listindex = i
                    End If
              Next
        Else
              .listindex = 0
        End If
    End With
    With e("cboFrmType")
        .EnabledTooltipText = FRAME_TYPE
    End With
    
    '-------------------------------------------------------------------------
    ' control: lbl_publish (show)
    '-------------------------------------------------------------------------
    With c("lbl_publish")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: lbl_publish
    End With
    
    '-------------------------------------------------------------------------
    ' control: cbo_publish (show)
    '-------------------------------------------------------------------------
    With c("cbo_publish")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        .Clear
        If (r.v("LIN_NodeList_EXIST")) Then
        For i = 1 To n.Count
            Set uNode = n.item(i)
            .AddItem (uNode.Name)
        Next
        End If
        
        Call ShowPublisher(ps, True)
    End With
    With e("cbo_publish")
        .EnabledTooltipText = FRAME_PUBLISHER
    End With
    
    '-------------------------------------------------------------------------
    ' control: lstSignal (show)
    '-------------------------------------------------------------------------
    With c("lstSignal")
        bDisabled = (Not (r.v("LIN_FrameList_EXIST") = 1))
        .Enabled = Not bDisabled
        
        .Clear
        If r.v("LIN_NodeList_EXIST") Then
        Set uNode = n.item(r.v(sVarPre & "_PubIndex") + 1)
        End If

        If (uNode.SPubCount) Then
            For i = 0 To uNode.SPubCount - 1
                If (uNode.SigPublisher(i) <> "") Then
                    .AddItem (uNode.SigPublisher(i))
                End If
            Next
            If ((c("lstSignal").ListCount - 1) <= r.v(sVarPre & "_SigIndex")) Then
                r.v(sVarPre & "_SigIndex") = c("lstSignal").ListCount - 1
            End If
            .listindex = r.v(sVarPre & "_SigIndex")
        End If
    End With
    With e("lstSignal")
        .EnabledTooltipText = FRAME_SIGNALS
    End With
    
  End If

  OnShowPageFrame = True
  Exit Function

OnShowPageFrameError:
errorbox "Error - " & PageName, Err.Description
  Exit Function
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Frame' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageFrame(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageFrameError

  OnButtonClickOnPageFrame = False
  
  Dim c         As Object
  Dim r         As ProjectData
  Dim listindex As Integer
  Dim frmIndex  As Integer
  Dim i         As Integer
  Dim j         As Integer
  Dim k         As Integer
  Dim bFlag     As Boolean
  Dim bSOFlag   As Boolean
  Dim uFrame    As New LinFrame
  Dim uNode     As New LinNode
  Dim tNode     As New LinNode
  Dim uSignal   As New LinSignal
  Dim tSignal   As New LinSignal
  Dim SigName   As String
  Dim SigOffset As Integer
  Dim tsigoffset As Integer
  Dim SigSize    As Integer
  Dim tmpName    As String
  Dim sEvtSPRDStr    As String

  Set r = ps.ProjectData
  Set c = ps.ControlCollection

  Select Case (Controlname)
  
    '---------------------------------------------------------------------
    ' control: btnSignalAdd (action)
    '---------------------------------------------------------------------
    Case "btnSignalAdd"
        If (c("lstSignal").ListCount And c("lstSignal").listindex >= 0) Then
            If r.v("LIN_FrameList_EXIST") Then
                Set uFrame = p.item(r.v("LIST_FRAME_INDEX") + 3)
            End If
            If r.v("LIN_NodeList_EXIST") Then
               Set uNode = n.item(r.v("LIN_PubIndex") + 1)
            End If
    
            SigName = c("lstSignal").List(c("lstSignal").listindex)
            
            For j = 1 To s.Count
              Set tSignal = s.item(j)
              If tSignal.Name = SigName Then
                Set uSignal = s.item(j)
              End If
            Next
            SigOffset = uSignal.Offset
            SigSize = uSignal.Size
            
            If (c("lstData").ListCount) Then
            
                bSOFlag = False
                For i = 0 To (c("lstData").ListCount - 1)
                  tmpName = (c("lstData").List(i))
                  For j = 1 To s.Count
                    Set tSignal = s.item(j)
                    If tSignal.Name = tmpName Then
                    tsigoffset = tSignal.Offset
                    End If
                  Next j
                   If (tsigoffset = SigOffset) Then
                      bSOFlag = True
                      Exit For
                   End If
                Next i
            
                If (bSOFlag <> True) Then
                'Check for the Signal size and Frame size
                    If (((SigOffset + SigSize) - 1) <= ((uFrame.Length * 8) - 1)) Then
                      bFlag = True
                      For j = SigOffset To (SigOffset + SigSize) - 1
                        If (uFrame.FrmSignals(j) <> "") Then
                        bFlag = False
                        Exit For
                        End If
                      Next j
                    Else
                      UserMessage SIGNAL_EXCEEDS_FRAMELENGTH
                    End If
        
                    If (bFlag = True) Then
                    'Signal packing to a Frame
                      With c("lstData")
                          .AddItem (SigName)
                      End With
                      
                     'Adding Frame Subscribers
'                      AddFrameSubscribers SigName, uFrame
                      For j = SigOffset To (SigOffset + SigSize) - 1
                        uFrame.FrmSignals(j) = SigName
                        uFrame.FrmSigCount = uFrame.FrmSigCount + 1
                      Next j
                      AddFrameSubscribers SigName, uFrame
                    Else
                      UserMessage SIGNAL_OUT_OF_RANGE
                    End If
                Else
                  MsgBox SIGNAL_OFFSET_IN_FRAME
                End If
               ' Next
            Else
              'Check for the Signal size and Frame size
              If (((SigOffset + SigSize) - 1) <= ((uFrame.Length * 8) - 1)) Then
                With c("lstData")
                  .AddItem (SigName)
                End With
                'Packing the first signal to a frame
                For j = SigOffset To (SigOffset + SigSize) - 1
                  uFrame.FrmSignals(j) = SigName
                  uFrame.FrmSigCount = uFrame.FrmSigCount + 1 'uFrame.Length * 8
                Next j
                AddFrameSubscribers SigName, uFrame    'Adding Frame Subscribers
              Else
                UserMessage SIGNAL_EXCEEDS_FRAMELENGTH
              End If
           End If
        End If
    '---------------------------------------------------------------------
    ' control: btnSignalDel (action)
    '---------------------------------------------------------------------
    Case "btnSignalDel"
        If (c("lstData").ListCount And c("lstData").listindex >= 0) Then
          If r.v("LIN_FrameList_EXIST") Then
            Set uFrame = p.item(r.v("LIST_FRAME_INDEX") + 3)
          End If
    
          If (uFrame.FrmSigCount) Then
            For i = 0 To ((uFrame.Length * 8) - 1)
              If (uFrame.FrmSignals(i) = c("lstData").List(c("lstData").listindex)) Then
                uFrame.FrmSignals(i) = ""
              End If
            Next i
                
            For Each tNode In n
            For k = 0 To (tNode.SSubCount - 1)
              If (tNode.SigSubscriber(k) = c("lstData").List(c("lstData").listindex)) Then
                For j = 0 To (tNode.FSubCount - 1)
                If (uFrame.Name = tNode.FrmSubscriber(j)) Then
                  tNode.FrmSubscriber(j) = ""
                  tNode.FSubCount = tNode.FSubCount - 1
                End If
                Next j
              End If
            Next k
            Next
            
            With c("lstData")
              .RemoveItem (c("lstData").listindex)
              .listindex = c("lstData").ListCount - 1
            End With
          End If
        End If

    '---------------------------------------------------------------------
    ' control: btnFrmAdd (action)
    '---------------------------------------------------------------------

    Case "btnFrmAdd"
    
        If (r.v("LIN_NodeList_EXIST")) Then
        If (c("lstFrmList").ListCount) Then
            FrmKey = GetIndex(ps, "lstFrmList")
        Else
            FrmKey = 0
        End If

        frmIndex = FrmKey + 1
        If (p.Count < iMaxFrm) Then
            With c("lstFrmList")
                .AddItem ("Frame" & frmIndex)
                r.v("LIST_FRAME_INDEX") = .ListCount - 1
                .listindex = .ListCount - 1
            End With
            
            uFrame.Name = "Frame" & frmIndex
            uFrame.ID = FrmKey
            uFrame.MsgID = FrmKey
            If (FrmKey < 32) Then
                uFrame.Length = 2
            ElseIf (FrmKey < 48) Then
                uFrame.Length = 4
            Else
                uFrame.Length = 8
            End If
            For i = 0 To (uFrame.Length * 8) - 1
            uFrame.FrmSignals(i) = ""
            Next
            uFrame.MaxPeriod = 100
            uFrame.MinPeriod = 10
            uFrame.FrmType = "Unconditional"
            
            
            If (c("cbo_publish").ListCount) Then
                Set uNode = n.item(1)
                uNode.FrmPublisher(uNode.FPubCount) = uFrame.Name
                uNode.FPubCount = uNode.FPubCount + 1
            End If
            'Add the frame details to DAvE collection
            p.Add uFrame
            'If (r.v("LIN_FrameList_EXIST")) Then
                'Remove the existing ObjectCollection to avoid duplicates
                ObjectCollection.Remove "LinFrames"
            'End If
            'Add to the collection of Object collections
            ObjectCollection.Add p, "LinFrames"
        End If
         
        r.v("LIN_FrameList_EXIST") = 1
        c("btnFrmDel").Enabled = True
        iFrmAccount = 1
        
        Set uFrame = p.item(c("lstFrmList").ListCount)
        c("txtFrameName").Text = uFrame.Name
        If (uFrame.FrmType <> "Sporadic") Then
            c("txtID").Text = uFrame.ID
            c("txt_msgid").Text = FormatTextOutput(uFrame.MsgID, "H4")
        Else
            c("txtID").Text = ""
            c("txt_msgid").Text = ""
        End If
        c("txtMaxft").Text = uFrame.MaxPeriod
        c("txtMinft").Text = uFrame.MinPeriod
        
        With c("cboFrmType")
            .Clear
            .AddItem ("Unconditional")
            .AddItem ("Event_Triggered")
            .AddItem ("Sporadic")
              For i = 0 To .ListCount - 1
                    If (uFrame.FrmType = .List(i)) Then
                        .listindex = i
                    End If
              Next i
        End With
        sEvtSPRDStr = ""
        If (uFrame.FrmType = "Event_Triggered" Or uFrame.FrmType = "Sporadic") Then
            If (uFrame.EvtSPRDCount) Then
                sEvtSPRDStr = JoinArray(frmIndex, ",")
            End If
        End If
        c("txtEvtSPRDid").Text = sEvtSPRDStr
        With c("cbo_size")
            .Clear
            For i = 1 To 8
                .AddItem (i)
            Next i
            .listindex = uFrame.Length - 1
        End With
        Call ShowPublisher(ps, False)
        Call EnableOrDisableControls(ps, "Frames", uFrame)
        Else
            UserMessage "There are no nodes in the cluster."
        End If
    '---------------------------------------------------------------------
    ' control: btnFrmDel (action)
    '---------------------------------------------------------------------
    Case "btnFrmDel"
 
        listindex = c("lstFrmList").listindex
        frmIndex = listindex + 1
        Set uFrame = p.item(frmIndex + 2)
        RemoveOldPublisher (uFrame)
        p.Remove (frmIndex + 2)
        c("lstFrmList").RemoveItem (listindex)
        If (c("lstFrmList").ListCount) Then
            FrmKey = GetIndex(ps, "lstFrmList")
        End If
        
        If (c("lstFrmList").ListCount) Then
            If (Not (c("lstFrmList").ListCount <= listindex)) Then
                c("lstFrmList").listindex = r.v("LIST_FRAME_INDEX")
            Else
                r.v("LIST_FRAME_INDEX") = c("lstFrmList").ListCount - 1
                c("lstFrmList").listindex = r.v("LIST_FRAME_INDEX")
            End If
            If (r.v("LIN_NodeList_EXIST")) Then
                Call ShowPublisher(ps, False)
            End If
            Set uFrame = p.item(r.v("LIST_FRAME_INDEX") + 3)
            c("txtFrameName").Text = uFrame.Name
            If (uFrame.FrmType <> "Sporadic") Then
                c("txtID").Text = uFrame.ID
                c("txt_msgid").Text = FormatTextOutput(uFrame.MsgID, "H4")
            Else
                c("txtID").Text = ""
                c("txt_msgid").Text = ""
            End If
            c("txtMaxft").Text = uFrame.MaxPeriod
            c("txtMinft").Text = uFrame.MinPeriod
            For i = 0 To c("cboFrmType").ListCount - 1
                If (c("cboFrmType").List(i) = uFrame.FrmType) Then
                    c("cboFrmType").listindex = i
                End If
            Next
            sEvtSPRDStr = ""
            If (uFrame.FrmType = "Event_Triggered" Or uFrame.FrmType = "Sporadic") Then
                If (uFrame.EvtSPRDCount) Then
                    sEvtSPRDStr = JoinArray(r.v("LIST_FRAME_INDEX") + 3, ",")
                End If
            End If
            c("txtEvtSPRDid").Text = sEvtSPRDStr
            c("cbo_size").listindex = uFrame.Length - 1
        Else
            r.v("LIN_FrameList_EXIST") = 0
            r.v("LIST_FRAME_INDEX") = 0
            iFrmAccount = 0
            ObjectCollection.Remove "LinFrames"
            c("txtFrameName").Text = ""
            c("txtID").Text = ""
            c("txt_msgid").Text = ""
            c("txtMaxft").Text = "0"
            c("txtMinft").Text = "0"
            c("cbo_size").Clear
            c("cboFrmType").Clear
            c("btnFrmDel").Enabled = False
            c("txtEvtSPRDid").Text = ""
        End If

        Call EnableOrDisableControls(ps, "Frames", uFrame)
            If (uFrame.FrmType <> "Unconditional") Then
            c("btnSignalAdd").Enabled = False
            c("btnSignalDel").Enabled = False
            End If
        
    Case Else
  End Select
  
  
  OnButtonClickOnPageFrame = True
  Exit Function

OnButtonClickOnPageFrameError:
errorbox "Error " & Controlname, Err.Description
  Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function GetIndex(ps As Object, ControlIndex As String) As Integer
On Error GoTo GetIndexError

GetIndex = 0
Dim c As Object
Dim iCount As Integer
Dim i As Integer
Dim sList As String
Dim sIndex As String
Dim iIndex As Integer
Dim tmpIndex As Integer
Dim sKey As String
Dim iDigit As Integer

Set c = ps.ControlCollection
iCount = (c(ControlIndex).ListCount) - 1
iIndex = 0

For i = 0 To iCount
    sList = c(ControlIndex).List(i)
    sKey = ""
    For iDigit = 1 To 2
        sIndex = Right(sList, iDigit)
        If (IsNumeric(sIndex)) Then
            sKey = sIndex
        End If
    
    Next iDigit
    If (sKey <> "") Then
        tmpIndex = CInt(sKey)
    End If
    If (tmpIndex > iIndex) Then
        iIndex = tmpIndex
    End If
Next i

GetIndex = iIndex
Exit Function

GetIndexError:
errorbox "Error", Err.Description
Exit Function
End Function




'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'Schedule'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageSchedule(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageSchedule = False

  If (Not ps.AddPage("Schedule")) Then Exit Function

  OnLoadPageSchedule = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPageSchedule(ps As Object, PageName As String) As Boolean
  On Error Resume Next

  OnChangingPageSchedule = False
  
  If (Not ps.ExtenderCollection("Schedule").Loaded) And (PageName = "Schedule") Then
    ps.ExtenderCollection("Schedule").Loaded = True

    '-------------------------------
    ' frame: frmFrmLst
    '-------------------------------
    If (Not ps.AddFrame("frmFrmLst", 120, 120, 2300, 5000, "Frame List")) Then Exit Function
        If (Not ps.Addlistbox("lstFrmLst", 240, 360, 1800, 4340)) Then Exit Function

    '-------------------------------
    ' frame: frmSchd
    '-------------------------------
    If (Not ps.AddFrame("frmSchd", 2540, 120, 3220, 5000, "Schedule")) Then Exit Function
        If (Not ps.AddLabel("lblSchName", 0, 240, 360, 1500, 360, "Schedule Name")) Then Exit Function
        If (Not ps.AddLabel("lblSchFrms", 0, 240, 650, 1500, 360, "Frames")) Then Exit Function
        If (Not ps.Addtext("txtSchd", 1500, 360, 1500, 360)) Then Exit Function
        If (Not ps.Addlistbox("lstSchd", 240, 900, 2740, 3180)) Then Exit Function
        If (Not ps.AddButton("btnSchdAdd", 240, 4320, 1080, 315, "Add")) Then Exit Function
        If (Not ps.AddButton("btnSchdDel", 1860, 4320, 1080, 315, "Delete")) Then Exit Function

    '-------------------------------
    ' frame: frmSchdLst
    '-------------------------------
    If (Not ps.AddFrame("frmSchdLst", 5880, 120, 2760, 5000, "Schedule List")) Then Exit Function
        If (Not ps.Addlistbox("lstSLst", 240, 360, 2280, 3780)) Then Exit Function
        If (Not ps.AddButton("btnSLAdd", 240, 4320, 1080, 315, "Add")) Then Exit Function
        If (Not ps.AddButton("btnSLDel", 1440, 4320, 1155, 315, "Delete")) Then Exit Function

  End If
  OnChangingPageSchedule = True
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageSchedule(ps As Object, Controlname As String, PageName As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageScheduleError

  OnShowPageSchedule = False

  Dim r As Object
  Dim c As Object
  Dim e As Object
  Dim i As Integer
  Dim SchIndex As Integer
  Dim SCHfrm As Integer
  Dim bDisabled As Boolean
  Dim sVarPre   As String
  Dim uFrame As LinFrame
  Dim uSchedule As LinSchedule
  
  Set uFrame = New LinFrame
  Set uSchedule = New LinSchedule

  sVarPre = "LIN"
 
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (PageName = "Schedule") Then
    '-------------------------------------------------------------------------
    ' page: Schedule (action)
    '-------------------------------------------------------------------------
        If r.v("LIN_ScheduleList_EXIST") Then
            SchIndex = r.v("LIST_SCH_INDEX") + 1
        End If
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: lstFrmLst (action)
        '---------------------------------------------------------------------
        Case "lstFrmLst"
             r.v("LIST_SCHfrm_INDEX") = c("lstFrmLst").listindex

        '---------------------------------------------------------------------
        ' control: txtSchd (action)
        '---------------------------------------------------------------------
        Case "txtSchd"
             r.v(sVarPre & "_Schedule_Name") = v(1)
             Set uSchedule = st.item(SchIndex)
             If (Not CheckListNames(ps, "lstSLst", r.v(sVarPre & "_Schedule_Name"))) Then
             uSchedule.Name = r.v(sVarPre & "_Schedule_Name")
             Else
                UserMessage SAME_LIST_NAME
             End If
            
        '---------------------------------------------------------------------
        ' control: lstSchd (action)
        '---------------------------------------------------------------------
        Case "lstSchd"
                r.v("LIST_SCHxFRMs_INDEX") = c("lstSchd").listindex

        '---------------------------------------------------------------------
        ' control: lstSLst (action)
        '---------------------------------------------------------------------
        Case "lstSLst"
            r.v("LIST_SCH_INDEX") = c("lstSLst").listindex
            SchIndex = r.v("LIST_SCH_INDEX") + 1
            Set uSchedule = st.item(SchIndex)
        Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Schedule (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: lstFrmLst (show)
    '-------------------------------------------------------------------------
    With c("lstFrmLst")
      bDisabled = (r.v("LIN_ScheduleList_EXIST"))
      .Enabled = bDisabled
      
      .Clear
      If (r.v("LIN_FrameList_EXIST")) Then
            For i = 1 To p.Count
                Set uFrame = p.item(i)
                .AddItem (uFrame.Name)
            Next
            .listindex = r.v("LIST_SCHfrm_INDEX")
      End If

    End With
    With e("lstFrmLst")
        .EnabledTooltipText = SCH_FRMLST
    End With

    '-------------------------------------------------------------------------
    ' control: txtSchd (show)
    '-------------------------------------------------------------------------
    With c("txtSchd")
      bDisabled = (r.v("LIN_ScheduleList_EXIST"))
      .Enabled = bDisabled

      If (r.v("LIN_ScheduleList_EXIST")) Then
         Set uSchedule = st.item(SchIndex)
         .Text = uSchedule.Name
      Else
         .Text = ""
      End If
    End With
    With e("txtSchd")
        .EnabledTooltipText = SCH_NAME
    End With

    '-------------------------------------------------------------------------
    ' control: lstSchd (show)
    '-------------------------------------------------------------------------
    With c("lstSchd")
      bDisabled = (r.v("LIN_ScheduleList_EXIST"))
      .Enabled = bDisabled

      .Clear
      If (r.v("LIN_ScheduleList_EXIST")) Then
          Set uSchedule = st.item(SchIndex)
          If (uSchedule.Count) Then
                'Display the Frames for the schedule
                For i = 0 To (uSchedule.Count - 1)
                     If uSchedule.Frames(i) <> "" Then
                        .AddItem (uSchedule.Frames(i))
                     End If
                Next
                'Adjusting the Index for the list
                If (c("lstSchd").ListCount) Then
                    If ((c("lstSchd").ListCount) <= r.v("LIST_SCHxFRMs_INDEX")) Then
                            r.v("LIST_SCHxFRMs_INDEX") = c("lstSchd").ListCount - 1
                    End If
                    .listindex = r.v("LIST_SCHxFRMs_INDEX")
                End If
          End If
      End If
    End With
    With e("lstSchd")
        .EnabledTooltipText = SCH_SCHEDULE
    End With

    '-------------------------------------------------------------------------
    ' control: btnSchdAdd (show)
    '-------------------------------------------------------------------------
    With c("btnSchdAdd")
      bDisabled = (r.v("LIN_ScheduleList_EXIST"))
      .Enabled = bDisabled
    End With
    With e("btnSchdAdd")
        .EnabledTooltipText = SCH_BTNFRM
    End With

    '-------------------------------------------------------------------------
    ' control: btnSchdDel (show)
    '-------------------------------------------------------------------------
    With c("btnSchdDel")
        If (c("lstSchd").ListCount) Then
        .Enabled = True
        Else
        .Enabled = False
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: lstSLst (show)
    '-------------------------------------------------------------------------
    With c("lstSLst")
      .Clear
      If (r.v("LIN_ScheduleList_EXIST")) Then
            'Display the schedules from DAvEcollection
            For i = 1 To st.Count
                Set uSchedule = st.item(i)
                .AddItem (uSchedule.Name)
            Next
            'Adjusting the Index for the list
            .listindex = r.v("LIST_SCH_INDEX")
      End If
      
    End With
    With e("lstSLst")
        .EnabledTooltipText = SCH_SCHLST
    End With

    '-------------------------------------------------------------------------
    ' control: btnSLAdd (show)
    '-------------------------------------------------------------------------
    With c("btnSLAdd")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: btnSLAdd
      .Enabled = (r.v("LIN_FrameList_EXIST"))
    End With
    With e("btnSLAdd")
        .EnabledTooltipText = SCH_BTNADD
    End With

    '-------------------------------------------------------------------------
    ' control: btnSLDel (show)
    '-------------------------------------------------------------------------
    With c("btnSLDel")
      ' INSERT THE STATEMENTS WHICH HAVE TO BE EXECUTED
      ' TO REFRESH THE CONTENTS OF THE CONTROL: btnSLDel
      .Enabled = (r.v("LIN_ScheduleList_EXIST"))
    End With
   
  End If

  OnShowPageSchedule = True
  Exit Function

OnShowPageScheduleError:
errorbox "Error " & PageName, Err.Description
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Schedule' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageSchedule(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageScheduleError

  OnButtonClickOnPageSchedule = False
  
  Dim SchIndex As Integer
  Dim listindex As Integer
  Dim SCHfrm As Integer
  Dim i As Integer
  Dim iFrmcount As Integer
  Dim jFrmcount As Integer
    
  Dim c As Object
  Dim r As Object
  Dim uSchedule As LinSchedule
  
  Set c = ps.ControlCollection
  Set r = ps.ProjectData
  Set uSchedule = New LinSchedule
  Select Case (Controlname)
    '---------------------------------------------------------------------
    ' control: btnSchdAdd (action)
    '---------------------------------------------------------------------
    Case "btnSchdAdd"
        'Adding Frames to a Schedule
         'Get the index of the selected item
         
         If r.v("LIN_ScheduleList_EXIST") Then
                SchIndex = r.v("LIST_SCH_INDEX") + 1
                Set uSchedule = st.item(SchIndex)
         End If
         
         If (CheckEvtSPRDFrm(uSchedule.Name, c("lstFrmLst").List(c("lstFrmLst").listindex))) Then
         'Adding selected Frame to a Schedule
         With c("lstSchd")
              .AddItem (c("lstFrmLst").List(c("lstFrmLst").listindex))
              .listindex = .ListCount - 1
              r.v("LIST_SCHxFRMs_INDEX") = .ListCount - 1
         End With
         c("btnSchdDel").Enabled = True
         'Adding selected Frame to the Schedule object of DAvECollection
         If r.v("LIN_ScheduleList_EXIST") Then
            uSchedule.Frames(uSchedule.Count) = c("lstFrmLst").List(c("lstFrmLst").listindex)
            uSchedule.Count = uSchedule.Count + 1
         End If
         End If
    '---------------------------------------------------------------------
    ' control: btnSchdDel (action)
    '---------------------------------------------------------------------
    Case "btnSchdDel"
         'Deleting the selected item from the schedule object
         'Deleting the selected item from the schedule object's FramesList
         If (c("lstSchd").ListCount) Then
         If r.v("LIN_ScheduleList_EXIST") Then
               SchIndex = r.v("LIST_SCH_INDEX") + 1
               Set uSchedule = st.item(SchIndex)
               If (uSchedule.Count) Then
                    For iFrmcount = 0 To (uSchedule.Count - 1)
                         If (iFrmcount = (c("lstSchd").listindex)) Then
                            For jFrmcount = iFrmcount To (uSchedule.Count - 2)
                                uSchedule.Frames(jFrmcount) = uSchedule.Frames(jFrmcount + 1)
                            Next
                            uSchedule.Count = uSchedule.Count - 1
                        End If
                    Next
               End If
         End If
         'Deleting the selected item from the Frameslist of the schedule
         With c("lstSchd")
              .RemoveItem (c("lstSchd").listindex)
              .listindex = c("lstSchd").ListCount - 1
              SchKey = SchKey + 1
         End With
         If ((c("lstSchd").ListCount) = 0) Then
         c("btnSchdDel").Enabled = False
         End If
         End If
    '---------------------------------------------------------------------
    ' control: btnSLAdd (action)
    '---------------------------------------------------------------------
    Case "btnSLAdd"
          If (r.v("LIN_FrameList_EXIST")) Then
           'Adding Schedules to DAvE collection
            'Assign index of the new schedule
            If (c("lstSLst").ListCount) Then
                  SchKey = GetIndex(ps, "lstSLst")
            Else
                  SchKey = 0
            End If
            SchIndex = SchKey + 1
            'Adding a new Schedule to the Schedule table
            With c("lstSLst")
                  .AddItem ("Schedule" & SchIndex)
                  r.v("LIST_SCH_INDEX") = (c("lstSLst").ListCount - 1)
                  .listindex = r.v("LIST_SCH_INDEX")
            End With

            uSchedule.ID = SchIndex
            uSchedule.Name = "Schedule" & SchIndex
            uSchedule.Count = 0

            'Adding Frames to schedule
            'Add the Schedule details to DAvE collection
            st.Add uSchedule
            If (r.v("LIN_ScheduleList_EXIST")) Then
                ObjectCollection.Remove "LinSchedules"
            End If
            'Add to collection of Object collections
            ObjectCollection.Add st, "LinSchedules"

            r.v("LIN_ScheduleList_EXIST") = 1
            c("btnSLDel").Enabled = True
            Set uSchedule = st.item(r.v("LIST_SCH_INDEX") + 1)
                c("txtSchd").Text = uSchedule.Name
                If uSchedule.Count = 0 Then
                    c("lstSchd").Clear
                End If
                
            'Enable the controls in the Schedule page
            Call EnableOrDisableControls(ps, "Schedules")
          Else
            UserMessage "There are no frames packed with signals."
          End If

    '---------------------------------------------------------------------
    ' control: btnSLDel (action)
    '---------------------------------------------------------------------
    Case "btnSLDel"
      If (c("lstSLst").ListCount) Then
      If (r.v("LIN_ScheduleList_EXIST")) Then
       'Remove schedule from the item from DAvEcollection
         listindex = c("lstSLst").listindex
         SchIndex = listindex + 1
         'remove the selected the item from DAvEcollection
         st.Remove (SchIndex)
         c("lstSLst").RemoveItem (listindex)
         If (c("lstSLst").ListCount) Then
            SchKey = GetIndex(ps, "lstSLst")
         End If
         
         'Adjusting the index fot the LIST
         If (c("lstSLst").ListCount) Then
            If (Not (c("lstSLst").ListCount <= listindex)) Then
                c("lstSLst").listindex = r.v("LIST_SCH_INDEX")
            Else
                r.v("LIST_SCH_INDEX") = c("lstSLst").ListCount - 1
                c("lstSLst").listindex = r.v("LIST_SCH_INDEX")
            End If
            
            Set uSchedule = st.item(r.v("LIST_SCH_INDEX") + 1)
            c("txtSchd").Text = uSchedule.Name
            With c("lstSchd")
              .Clear
              If (uSchedule.Count) Then
                'Display the Frames for the schedule
                For i = 0 To (uSchedule.Count - 1)
                  If uSchedule.Frames(i) <> "" Then
                  .AddItem (uSchedule.Frames(i))
                  End If
                Next
                'Adjusting the Index for the list
                If (c("lstSchd").ListCount) Then
                  If ((c("lstSchd").ListCount) <= r.v("LIST_SCHxFRMs_INDEX")) Then
                  r.v("LIST_SCHxFRMs_INDEX") = c("lstSchd").ListCount - 1
                  End If
                  .listindex = r.v("LIST_SCHxFRMs_INDEX")
                End If
              End If
            End With
         Else
            r.v("LIN_ScheduleList_EXIST") = 0
            r.v("LIST_SCH_INDEX") = 0
            ObjectCollection.Remove "LinSchedules"
            c("txtSchd").Text = ""
            c("lstSchd").Clear
            c("btnSLDel").Enabled = False
        End If
        
          
        Call EnableOrDisableControls(ps, "Schedules")
      Else
        UserMessage "There are no schedules configured."
      End If
      End If
    Case Else
  End Select
 

  OnButtonClickOnPageSchedule = True
  Exit Function

OnButtonClickOnPageScheduleError:
errorbox "Error " & Controlname, Err.Description
  Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function JoinArray(iIndex As Integer, delimiter As String) As String

Dim sString As String
Dim iElement As Integer
Dim iCharNo As Integer
Dim uFrame As New LinFrame

Set uFrame = p.item(iIndex)

    sString = ""
    For iElement = 0 To (uFrame.EvtSPRDCount - 1)
        sString = sString & CStr(uFrame.EvtSPRDFrm(iElement)) & delimiter
    Next
    iCharNo = Len(sString) - 1
    sString = Left(sString, iCharNo)

JoinArray = sString
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function SplitArray(sText As String, delimiter As String) As Variant

Dim sSingleChar As String
Dim sArrayItem  As String
Dim i           As Integer
Dim j           As Integer
Dim k           As Integer
Dim tempArray(60) As Integer

j = 0
For i = 1 To Len(sText)
    sSingleChar = Mid(sText, i, 1)
    If (IsNumeric(sSingleChar)) Then
        sArrayItem = sArrayItem & sSingleChar
    ElseIf (sArrayItem <> "") Then
        tempArray(j) = CInt(sArrayItem)
        j = j + 1
        iArrayCount = j
        sArrayItem = ""
    End If
Next
If (IsNumeric(sArrayItem)) Then
    tempArray(j) = CInt(sArrayItem)
    iArrayCount = j + 1
End If
SplitArray = tempArray
  
End Function
Public Sub RemoveOldPublisher(uFrame As LinFrame)

Dim i       As Integer
Dim uNode   As New LinNode

For Each uNode In n
    For i = 0 To uNode.FPubCount - 1
        If (uNode.FrmPublisher(i) = uFrame.Name) Then
            uNode.FrmPublisher(i) = ""
            Exit For
        End If
    Next
Next
For i = 0 To uFrame.FrmSigCount - 1
    uFrame.FrmSignals(i) = ""
Next i
End Sub
'*****************************************************************************
'Description:
'        This function is called from the OnShowPageFrame function of
'        the associated page Frame
'-----------------------------------------------------------------------------
'Parameters:
'        uNode               Node to be removed from FrameSubscribers list
'        uFrame              Frame Name
'*****************************************************************************
Public Sub RemoveOldSubscriber(uFrame As LinFrame, uNode As LinNode)

Dim i   As Integer
    For i = 0 To uNode.FSubCount - 1
        If (uNode.FrmSubscriber(i) = uFrame.Name) Then
            uNode.FrmSubscriber(i) = ""
        End If
    Next
End Sub
'*****************************************************************************
'Description:
'        This function is called from the OnButtonClickOnPageFrame function of
'        the associated page Frame
'-----------------------------------------------------------------------------
'Parameters:
'        SigName             Signal Name in the Node SignalSubscribers list
'        uFrame              Frame Name to be added to Node FrameSubscribers
'*****************************************************************************
Public Sub AddFrameSubscribers(SigName As String, uFrame As LinFrame)

Dim i       As Integer
Dim uNode   As New LinNode
Dim bFlag   As Boolean
    
    'Check Frame Subscribers
    For Each uNode In n
      bFlag = False
      If (uNode.FSubCount) Then
        For i = 0 To (uNode.FSubCount - 1)
          If (uNode.FrmSubscriber(i) = uFrame.Name) Then
            bFlag = True
          End If
        Next i
      End If
      'Adding Frame Subscribers
      If (Not bFlag) Then
        For i = 0 To (uNode.SSubCount - 1)
          If (SigName = uNode.SigSubscriber(i)) Then
            uNode.FrmSubscriber(uNode.FSubCount) = uFrame.Name
            uNode.FSubCount = uNode.FSubCount + 1
          End If
        Next i
      End If
    Next
End Sub

Public Function CheckEvtSPRDFrameID(iSelectedFrameID As Integer, iFrameID As Integer) As Boolean

CheckEvtSPRDFrameID = False

Dim i           As Integer
Dim j           As Integer
Dim vTempArray  As Variant
Dim uFrame      As New LinFrame
Dim bFlag       As Boolean

For Each uFrame In p
    If (((uFrame.ID = iFrameID) And (uFrame.FrmType = "Sporadic")) Or iFrameID = iSelectedFrameID) Then
        CheckEvtSPRDFrameID = True
        Exit Function
    End If
Next
End Function

Public Function CheckEvtSPRDFrm(SchName As String, iSelectedFrame As String) As Boolean

CheckEvtSPRDFrm = True

Dim i           As Integer
Dim j           As Integer
Dim k           As Integer
Dim uFrame      As New LinFrame
Dim Tframe      As New LinFrame
Dim uSchedule   As New LinSchedule
Dim TSchedule   As New LinSchedule
Dim bFlag       As Boolean

For i = 1 To p.Count
    Set uFrame = p.item(i)
    If (uFrame.Name = iSelectedFrame) Then
    Set Tframe = p.item(i)
    End If
Next
For i = 1 To st.Count
    Set uSchedule = st.item(i)
    If (uSchedule.Name = SchName) Then
    Set TSchedule = st.item(i)
    End If
Next


If (Tframe.FrmType = "Unconditional") Then
    If (TSchedule.Count) Then
        For i = 0 To TSchedule.Count - 1
            For k = 1 To p.Count
                Set uFrame = p.item(k)
                If (uFrame.Name = TSchedule.Frames(i)) Then
                Exit For
                End If
            Next

            If (uFrame.FrmType = "Event_Triggered" Or uFrame.FrmType = "Sporadic") Then
                If (uFrame.EvtSPRDCount) Then
                    For j = 0 To uFrame.EvtSPRDCount - 1
                        If (Tframe.ID = uFrame.EvtSPRDFrm(j)) Then
                            UserMessage "Schedule " & TSchedule.Name & " already have " & _
                            Tframe.Name & " inside the " & uFrame.FrmType & " Frame " & uFrame.Name & _
                            ". Please enter anyother Frame."
                            CheckEvtSPRDFrm = False
                            Exit Function
                        End If
                    Next j
                End If
            End If
            
        Next i
    End If
ElseIf (Tframe.FrmType = "Event_Triggered" Or Tframe.FrmType = "Sporadic") Then
        If (TSchedule.Count) Then
        For i = 0 To TSchedule.Count - 1
            For k = 1 To p.Count
                Set uFrame = p.item(k)
                If (uFrame.Name = TSchedule.Frames(i)) Then
                Exit For
                End If
            Next
            
            If (Tframe.EvtSPRDCount) Then
                    For j = 0 To Tframe.EvtSPRDCount - 1
                        If (uFrame.ID = Tframe.EvtSPRDFrm(j)) Then
                            UserMessage "Schedule " & TSchedule.Name & " already have Unconditional Frame " & _
                            uFrame.Name & ". " & Tframe.Name & " also has it. Please enter anyother Frame."
                            CheckEvtSPRDFrm = False
                            Exit Function
                        End If
                    Next j
            End If
       
        Next i
        End If

End If

End Function
Public Function FrameIDExists(iFrameID As Integer) As Boolean

Dim uFrame As New LinFrame
FrameIDExists = False

For Each uFrame In p
    If (iFrameID = uFrame.ID) Then
        FrameIDExists = True
    End If
Next
End Function
Public Sub DeleteArray(iArrayIndex As Integer, ByRef iArray() As String)

Dim i As Integer
Dim iSize As Integer

iSize = UBound(iArray) - LBound(iArray) + 1
iArray(iArrayIndex) = ""
For i = iArrayIndex To iSize - 2
    iArray(i) = iArray(i + 1)
Next
iSize = UBound(iArray) - 1
ReDim Preserve iArray(iSize)
End Sub
Public Sub EnableOrDisableControls(ps As Object, PageName As String, Optional uFrame As LinFrame)

Dim r As ProjectData
Dim c As Object
Dim bDisabled As Boolean
Dim i As Integer

Set r = ps.ProjectData
Set c = ps.ControlCollection

Select Case (PageName)

    '-------------------------------------------------------------------------
    ' NODES
    '-------------------------------------------------------------------------
    Case "Nodes"
    
        bDisabled = (r.v("LIN_NodeList_EXIST"))
        c("cboLnad").Enabled = bDisabled
        c("txtLp2min").Enabled = bDisabled
        c("txtLstmin").Enabled = bDisabled
        c("txtLmmlen").Enabled = bDisabled
        c("txtLnode").Enabled = bDisabled
        c("txtLrmrk").Enabled = bDisabled
        c("optLNOncf").Enabled = bDisabled
        c("optLncfdave").Enabled = bDisabled
        c("optLncfusr").Enabled = bDisabled
        
    '-------------------------------------------------------------------------
    ' SIGNALS
    '-------------------------------------------------------------------------
    Case "Signals"
    
        bDisabled = (r.v("LIN_SignalList_EXIST"))
        c("cboLssigsize").Enabled = bDisabled
        c("txtLssigname").Enabled = bDisabled
        c("optLsvalint").Enabled = bDisabled
        c("optLssigS").Enabled = bDisabled
        c("optLssigBA").Enabled = bDisabled
        c("txtLsint").Enabled = bDisabled
        c("txtLssigOff").Enabled = bDisabled
        c("cboLspub").Enabled = bDisabled
        c("lstLssub").Enabled = bDisabled
        c("lstLssub1").Enabled = bDisabled

    '-------------------------------------------------------------------------
    ' FRAMES
    '-------------------------------------------------------------------------
        
    Case "Frames"
        bDisabled = (r.v("LIN_FrameList_EXIST"))
        c("lstData").Enabled = bDisabled
        c("btnSignalAdd").Enabled = bDisabled
        c("btnSignalDel").Enabled = bDisabled
        c("txtFrameName").Enabled = bDisabled
        c("txtID").Enabled = bDisabled
        c("txt_msgid").Enabled = bDisabled
        c("txtMaxft").Enabled = bDisabled
        c("txtMinft").Enabled = bDisabled
        c("cbo_size").Enabled = bDisabled
        c("cboFrmType").Enabled = bDisabled
        c("cbo_publish").Enabled = bDisabled
        c("lstSignal").Enabled = bDisabled
        bDisabled = ((r.v("LIN_FrameList_EXIST")) And (uFrame.FrmType <> "Unconditional"))
        c("txtEvtSPRDid").Enabled = bDisabled

    '-------------------------------------------------------------------------
    ' SCHEDULES
    '-------------------------------------------------------------------------
    Case "Schedules"
    
        bDisabled = (r.v("LIN_ScheduleList_EXIST"))
        c("lstFrmLst").Enabled = bDisabled
        c("txtSchd").Enabled = bDisabled
        c("lstSchd").Enabled = bDisabled
        c("btnSchdAdd").Enabled = bDisabled
        bDisabled = c("lstSchd").ListCount
        c("btnSchdDel").Enabled = bDisabled
      
    Case Else
End Select
End Sub
Public Sub ShowPublisher(ps As Object, bPublishOnly As Integer)

Dim c           As Object
Dim r           As ProjectData
Dim i           As Integer
Dim bFlag       As Boolean
Dim sVarPre     As String
Dim sPubNode    As String
Dim sFrmPub     As String
Dim sSigName    As String

Dim uNode       As LinNode
Dim uFrame      As LinFrame

sVarPre = "LIN"
Set c = ps.ControlCollection
Set r = ps.ProjectData


If (r.v("LIN_FrameList_EXIST")) Then
    sFrmPub = c("lstFrmList").List(r.v("LIST_FRAME_INDEX"))
    sPubNode = GetPublisher(ps.ProjectData, sFrmPub, "Frame")
End If

If (c("cbo_publish").ListCount >= 1) Then
    For i = 0 To c("cbo_publish").ListCount - 1
        If (sPubNode = c("cbo_publish").List(i)) Then
            r.v(sVarPre & "_PubIndex") = i
            bFlag = False
            Exit For
        Else
            bFlag = True
        End If
    Next
    If (bFlag) Then
        r.v(sVarPre & "_PubIndex") = 0
    End If
        c("cbo_publish").listindex = r.v(sVarPre & "_PubIndex")
End If

If (Not bPublishOnly) Then
    '--------------------------------------------------------------
    'Published signal list
    '--------------------------------------------------------------
    If r.v("LIN_NodeList_EXIST") Then
        Set uNode = n.item(r.v(sVarPre & "_PubIndex") + 1)
    End If
    c("lstSignal").Clear
    If (uNode.SPubCount) Then
        For i = 0 To uNode.SPubCount - 1
            If (uNode.SigPublisher(i) <> "") Then
                c("lstSignal").AddItem (uNode.SigPublisher(i))
            End If
        Next
        If ((c("lstSignal").ListCount - 1) <= r.v(sVarPre & "_SigIndex")) Then
            r.v(sVarPre & "_SigIndex") = c("lstSignal").ListCount - 1
        End If
        c("lstSignal").listindex = r.v(sVarPre & "_SigIndex")
    End If
    
    '--------------------------------------------------------------
    'Signals packed in a frame
    '--------------------------------------------------------------
    If (r.v("LIN_FrameList_EXIST")) Then
        Set uFrame = p.item(r.v("LIST_FRAME_INDEX") + 3)
    End If
    c("lstData").Clear
    If (uFrame.FrmSigCount) Then
        For i = 0 To (uFrame.FrmSigCount) - 1
            If (uFrame.FrmSignals(i) <> "") Then
                If (sSigName <> uFrame.FrmSignals(i)) Then
                    c("lstData").AddItem (uFrame.FrmSignals(i))
                    sSigName = uFrame.FrmSignals(i)
                End If
            End If
        Next
    
        If (c("lstData").ListCount <= r.v("lstData_INDEX")) Then
            r.v("lstData_INDEX") = c("lstData").ListCount - 1
        End If
        c("lstData").listindex = r.v("lstData_INDEX")
    End If
End If

End Sub
'*****************************************************************************
'Description:
'        This function is called from the OnShowPageFrame function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        Frame1               - Frame that to be resixed
'        LSignal              - Signal that is updated.
'
'*****************************************************************************
Public Sub ResizeFrame(Framel As String, Lsignal As String)

Dim i           As Integer
Dim uSignal     As LinSignal
Dim uFrame      As LinFrame

For i = 1 To p.Count
    Set uFrame = p.item(i)
    If (uFrame.Name = Framel) Then
    Exit For
    End If
Next
For i = 1 To s.Count
    Set uSignal = s.item(i)
    If (uSignal.Name = Lsignal) Then
    Exit For
    End If
Next

If ((uSignal.Size + uSignal.Offset) > uFrame.Length - 1) Then
    For i = uSignal.Offset To (uFrame.Length * 8) - 1
    uFrame.FrmSignals(i) = ""
    Next
End If

End Sub
'*****************************************************************************
'Description:
'        This function is called from the OnShowPageFrame function
'        of the associated module
'-----------------------------------------------------------------------------
'
'*****************************************************************************
Public Function CheckListNames(ps As Object, Controlname As String, ListName As String) As Boolean

  Dim r As ProjectData
  Dim c As Object
  Dim i As Integer
  
  CheckListNames = False
  
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  
  For i = 0 To c(Controlname).ListCount - 1
    If (c(Controlname).List(i) = ListName) Then
        CheckListNames = True
        Exit For
    End If
  Next
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnShowPageFrame function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        iFrameID                - Frame ID and Msg ID They are alredy exists
'        iMsgID                  -
'
'*****************************************************************************
Public Function CheckForSameID(Optional iFrameID As Variant, Optional iMsgID As Variant) As Boolean

  Dim uFrame As New LinFrame
  CheckForSameID = False
  
  If (iFrameID) Then
    For Each uFrame In p
      If (uFrame.ID = iFrameID) Then
          CheckForSameID = True
          Exit For
      End If
    Next
  ElseIf (iMsgID) Then
    For Each uFrame In p
      If (uFrame.MsgID = iMsgID) Then
          CheckForSameID = True
          Exit For
      End If
    Next
  End If
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnShowPageFrame function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        iFrameID1               - Frames IDs 1 & 2 - whether both are
'        iFrameID2               - with same length.
'
'*****************************************************************************
Public Function CheckUNCDFrmID(iFrameID1 As Integer, iFrameID2 As Integer) As Boolean

  Dim uFrame As New LinFrame
  Dim iFrmID1 As Integer
  Dim iFrmID2 As Integer
  
  CheckUNCDFrmID = False
      
      For Each uFrame In p
      If (uFrame.ID = iFrameID1) Then
            iFrmID1 = uFrame.Length
      End If
      If (uFrame.ID = iFrameID2) Then
            iFrmID2 = uFrame.Length
      End If
      Next
      If (iFrmID1 = iFrmID2) Then
      CheckUNCDFrmID = True
      End If

End Function
'*****************************************************************************
'Description:
'        This function is called from the OnShowPageFrame function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        iFrameID1               - Frames IDs 1 & 2 - whether both are
'        iFrameID2               - from same Publisher.
'
'*****************************************************************************
Public Function CheckUNCDFrmPub(iFrmArr As Variant, iFrmCnt As Integer) As Boolean

  Dim uFrame As New LinFrame
  Dim uNode As New LinNode
  Dim sFrm1 As String
  Dim sFrm2 As String
  Dim i As Integer
  Dim j As Integer
  Dim k As Integer
  Dim bFrm1 As Boolean
  Dim bFrm2 As Boolean
  
  CheckUNCDFrmPub = True
      
If (iFrmCnt > 1) Then
        For i = 0 To iFrmCnt - 2
            For Each uFrame In p
                  If (uFrame.ID = iFrmArr(i)) Then
                  sFrm1 = uFrame.Name
                  End If
            Next
            For j = (i + 1) To iFrmCnt - 1
                For Each uFrame In p
                    If (uFrame.ID = iFrmArr(j)) Then
                    sFrm2 = uFrame.Name
                    End If
                      
                    For Each uNode In n
                        bFrm1 = False
                        bFrm2 = False
                        If (uNode.FPubCount > 1) Then
                            For k = 0 To uNode.FPubCount - 1
                              If (uNode.FrmPublisher(k) = sFrm1) Then
                                  bFrm1 = True
                              ElseIf (uNode.FrmPublisher(k) = sFrm2 And sFrm2 <> "") Then
                                  bFrm2 = True
                              End If
                            Next k
                            If (bFrm1 And bFrm2) Then
                                UserMessage "Frames " & sFrm1 & " " & sFrm2 & " are from same Publisher. " _
                                & SAME_FRAME_PUBLISHER
                                CheckUNCDFrmPub = False
                                Exit Function
                            End If
                        End If
                    Next
                Next
            Next j
        Next i
End If
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnLoadPageFrame function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        True               - Initialized Successfully
'        False              -
'
'*****************************************************************************
Public Function DiagnosticFrames() As Boolean
  On Error GoTo DiagnosticFramesError

  DiagnosticFrames = False

  Dim i As Integer
  Dim j As Integer
  Dim uFrame60    As New LinFrame
  Dim uFrame61    As New LinFrame
        'Initialize Diagnostic Frames -MasterReq & SlaveResp
        'MasterReq - Frame60
        uFrame60.Name = "MasterReq"
        uFrame60.ID = 60
        uFrame60.MsgID = 60
        uFrame60.FrmType = "Unconditional"
        uFrame60.Length = 8
        For i = 0 To (uFrame60.Length) - 1
            For j = (i * 8) To ((i + 1) * 8) - 1
            uFrame60.FrmSignals(j) = "MasterReqB" & i
            Next j
        Next i
        uFrame60.MaxPeriod = 100
        uFrame60.MinPeriod = 10
    'Add MasterReq to Frame ObectCollection
    p.Add uFrame60
    ObjectCollection.Add p, "LinFrames"
    
        'SlaveResp - Frame60
        uFrame61.Name = "SlaveResp"
        uFrame61.ID = 61
        uFrame61.MsgID = 61
        uFrame61.Length = 8
        uFrame61.FrmType = "Unconditional"
        For i = 0 To (uFrame61.Length) - 1
            For j = (i * 8) To ((i + 1) * 8) - 1
            uFrame61.FrmSignals(j) = "SlaveRespB" & i
            Next j
        Next i
        uFrame61.MaxPeriod = 100
        uFrame61.MinPeriod = 10
    'Add SlaveResp to Frame ObectCollection
    p.Add uFrame61
    ObjectCollection.Remove "LinFrames"
    ObjectCollection.Add p, "LinFrames"
    
    bDiagFrm = True
    DiagnosticFrames = True
    Exit Function
    
DiagnosticFramesError:
    errorbox "Error - DiagnosticFrames", Err.Description
    Exit Function

End Function
'*****************************************************************************
'Description:
'        This function is called from the OnButtonClickOnPageSignal function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        IndexPublisher  Publisher of the signal to be shown
'        InitEn          Factor to show the calling time <before or after config.>
'        sigIndex        listindex of the signal
'*****************************************************************************

Public Sub ShowSignalSubscribers(ps As Object, IndexPublisher As Integer, InitEn As Integer, Optional sigIndex As Integer)

  Dim c              As Object
  Dim r              As Object
  Dim i              As Integer
  Dim subcount       As Integer
  Dim pubindex       As Integer
  Dim test           As Integer
  Dim PublisherGet   As String
  Dim uSignal        As New LinSignal
  Dim uNode          As New LinNode
  Dim uFrame         As New LinFrame

  Set r = ps.ProjectData
  Set c = ps.ControlCollection

 With c("lstLssub")
  .Enabled = (r.v("LIN_SignalList_EXIST"))
  .Clear
  If n.Count Then
    If (n.Count > 8) Then
      subcount = 8
    Else
      subcount = n.Count
    End If
    For i = 1 To subcount
     Set uNode = n.item(i)
     .AddItem (uNode.Name)
     c("chk" & (i - 1)).Enabled = True
    Next
  End If
 End With

 With c("lstLssub1")
  .Enabled = (r.v("LIN_SignalList_EXIST"))
  .Clear
  If n.Count Then
    If (n.Count > 8) Then
      For i = 9 To n.Count
       Set uNode = n.item(i)
       .AddItem (uNode.Name)
       c("chk" & (i - 1)).Enabled = True
      Next
    End If
  End If
 End With

 For i = 0 To 15
  With c("chk" & i)
   If (InitEn = 1) Then
     If (i < 8) Then
       test = GetSubscriberY(ps, c("lstLssub").List(i), sigIndex, "Signal")
     Else
       test = GetSubscriberY(ps, c("lstLssub1").List(i - 8), sigIndex, "Signal")
     End If
   Else
     .Value = 0
   End If
      
   If (test = i + 1) Then
     .Value = 1
   Else
     .Value = 0
   End If
      
   If IndexPublisher = i Then
     .Value = 0
     .Enabled = False
   End If
  End With
 Next

End Sub

'*****************************************************************************
'Description:
'        This function is called from the OnButtonClickOnPageSignal function
'        of the associated module
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Signalname      Signal name to be removed from Subscribers and
'                        Publisher List
'*****************************************************************************

Public Sub DeleteSignal(ps As Object, SignalName As String)
On Error GoTo DeleteSignalError

  Dim c As Object
  Dim i As Integer
  Dim sc As Integer
  Dim uNode As LinNode
  
  Set c = ps.ControlCollection
  Set uNode = New LinNode

    For i = 1 To n.Count
    Set uNode = n.item(i)
      If uNode.SSubCount Then       'Delete Signal from Subscribers list.
        For sc = 0 To (uNode.SSubCount - 1)
        If (SignalName = uNode.SigSubscriber(sc)) Then
            uNode.SigSubscriber(sc) = ""
            End If
        Next sc
      End If

      If uNode.SPubCount Then       'Delete Signal from Publishers list.
        For sc = 0 To (uNode.SPubCount - 1)
        If (SignalName = uNode.SigPublisher(sc)) Then
          uNode.SigPublisher(sc) = ""
        End If
        Next sc
      End If
    Next i

  Exit Sub
DeleteSignalError:
  errorbox "ErrorDeleteSignal", Err.Description
 Exit Sub
End Sub
