How can I get the section names inside a project through VBA?


I'm making a new excel macro to automate some boring/repetitive tasks that I have to do inside Test.Lab, and I have hit a wall.

I need to get a list of the sections names inside a project, but was not able to get that in VBA.

So far I was able to put the sections inside a SearchBasket with the code bellow. But I can't find the section name property...

Any ideas on how to do that?

'Macro to process data in Test.Lab
Option Explicit
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems

Sub ACDC_Click()
    Dim tlApplication As LMSTestLabAutomation.Application
    Dim tlActiveBook As LMSTestLabAutomation.IBook          'Uma instância do Test.Lab (um Projeto)
    Dim tlDataWatch As LMSTestLabAutomation.DataWatch       'Monitor de eventos e dados (por exemplo um overload)
    Dim tlBlock As LMSTestLabAutomation.IBlock2             'Bloco de dados do TL (curvas etc)
    Dim tlSearchBasket As LMSTestLabAutomation.SearchBasket 'Resultados da pesquisa
    Dim tlSearchEngine As LMSTestLabAutomation.SearchEngine 'Lança procuras e retorna os resultados
    Dim tlExplorer As LMSTestLabAutomation.IExplorer        'Acesso ao explorer de dados do TL
    Dim tlSearchBusy As LMSTestLabAutomation.Watch          'Classe de objetos que faz algo quando uma dada propriedade muda/excede um valor, etc.
    Dim tlData As LMSTestLabAutomation.IData                'Permite decompor a analisar dados
    Dim tlStartPoint As LMSTestLabAutomation.StartPoint     'Ponto de partida para as pesquisa do SearchEngine
    Dim tlDataBase As LMSTestLabAutomation.IDatabase        'Permite o controle sobre as funções de gerenciamento de projetos
    Dim sProjectName As String
    Dim bBusySearch As Boolean
    Dim i As Integer
    'Retrieve the activebook and the database
    Set tlApplication = New LMSTestLabAutomation.Application
    Set tlActiveBook = tlApplication.ActiveBook
    Set tlDataBase = tlActiveBook.Database
    'Retrieve the Explorer
    Set tlDataWatch = tlActiveBook.FindDataWatch("Navigator_Explorer", 1000, 1, 1)
    Set tlExplorer = tlDataWatch.Data
    'Retrieve an instance of the SearchEngine
    Set tlSearchEngine = tlExplorer.Search
    Set tlSearchBusy = tlSearchEngine.State
    bBusySearch = tlSearchBusy.Data

    'Verify is the search feature is busy
    If (bBusySearch) Then
        MsgBox "Only 1 search can be performed at a time. The Macro will be ended", vbOKOnly, "Warning"
        tlSearchEngine.Search tlSearchEngine.StartPoint.ActiveProject, LMSTestLabAutomation.CONST_EnumSearchTypes.TestLab_Section, Nothing
    End If
    'Sleep until the results are found
    Sleep (5000) '(50000)

    'Retrieve the search results
    Set tlSearchBasket = tlSearchEngine.SearchBasket

End Sub

Re: How can I get the section names inside a project through VBA?

Siemens Genius Siemens Genius
Siemens Genius

If you want the section names from the currently active project, you can use something like the following subroutine:

    Public Function GetSectionList() As String()
        '*** This subroutine gets a list of sections
        '*** in the active database and returns them
        '*** in a string array.
        Dim TL As LMSTestLabAutomation.Application
        Dim TLDatabase As LMSTestLabAutomation.IDatabase
        Dim attr As LMSTestLabAutomation.AttributeMap
        Dim SectionNames() As String
        Set TL = New LMSTestLabAutomation.Application
        Set TLDatabase = TL.ActiveBook.Database
        Set attr = TLDatabase.SectionNames
        ReDim SectionNames(attr.Count - 1)
        For i = 0 To attr.Count - 1
            SectionNames(i) = attr.Item(i)

        GetSectionList = SectionNames
    End Function

If you want the sections from some other project (i.e. not the Active Project), you can change the way you get the TLDatabase object.  Or, you might want to use an IDataBrowser object instead.  Let me know if you need more details. 

Re: How can I get the section names inside a project through VBA?


Awesome, worked like a charm!

Thank you!