Please enable JavaScript to view this site.

IBM® SPSS® Amos™ 28

Navigation: Programming with Amos > Additional Programming Examples > Examples using the Amos Graphics classes

Use the Amos Graphics classes to name unobserved variables

Scroll Prev Top Next More

The following Amos Graphics plugin assigns names to any unnamed, unobserved variables. Latent variables are given names like "F1", "F2", and so forth. Unique variables are given names like "e1", "e2", and so forth.

Imports Microsoft.VisualBasic
Imports Amos
Imports AmosEngineLib.AmosEngine.TMatrixID
<System.ComponentModel.Composition.Export(GetType(IPlugin))>
Public Class CustomCode
    Implements IPlugin
 
    Public Function Mainsub() As Integer Implements IPlugin.Mainsub
        Const UniquePrefix = "e"
        Const LatentPrefix = "F"
        Dim UniqueCounter As Integer, LatentCounter As Integer
        UniqueCounter = LargestVariableNumber(UniquePrefix)
        LatentCounter = LargestVariableNumber(LatentPrefix)
        Dim E As PDElement
        For Each E In pd.PDElements
            If E.NameOrCaption = "" Then
                If E.IsUnobservedVariable Then
                    'E.Undraw()
                    If E.IsUniqueVariable Then
                        UniqueCounter += 1
                        E.NameOrCaption = UniquePrefix & UniqueCounter
                    Else
                        LatentCounter += 1
                        E.NameOrCaption = LatentPrefix & LatentCounter
                    End If
                    'E.Draw()
                End If
            End If
        Next
        pd.Refresh()
    End Function
 
    'Examine all variable names of the form, Prefix<Number>.
    'For example, if Prefix is "X", then examine variable
    'names like "X1", "X2", "X001", "X25", etc.
    'Return the largest value of <Number>, rounded off to an integer.
    Private Function LargestVariableNumber(ByVal Prefix As String) As Integer
        Dim E As PDElement, S1 As String, S2 As String
        For Each E In pd.PDElements
 
            S1 = Left$(E.NameOrCaption, Len(Prefix))
            S2 = Mid$(E.NameOrCaption, Len(Prefix) + 1)
 
            If UCase$(S1) = UCase$(Prefix) Then
                If IsNumeric(S2) Then
                    If S2 > LargestVariableNumber Then
                        LargestVariableNumber = S2
                    End If
                End If
            End If
 
        Next
    End Function
 
    Public Function Name() As String Implements IPlugin.Name
    End Function
 
    Public Function Description() As String Implements IPlugin.Description
    End Function
End Class

© 2021 Amos Development Corporation