Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Exporting Time Data to Excel via Testlab Automation

Hello,

 

currently I am trying to export time data from Testlab to Excel using VBA and Testlab Automation. Can anyone provide me with a minimal code-example to export one measured channel?

 

I do already manage to export post-processed blocks like Overall Level Data into Excel. But it seems that time data has to be handled somewhat differently. Here is what I do to get Overall Level Data:

 

set my_db = TL.ActiveBook.Database
Path = section & "/" & run_name & "/Tracked processing/Fixed sampling/Time/Sections/Overall level" Set att3 = my_db.ElementNames(Path) Path2 = Path & "/" & att3(0) att4 = my_db.ElementType(Path2) Set dataBlock = my_db.GetItem(Path2) Xvalues = dataBlock.Xvalues YRealValues = dataBlock.RealYValues

 

For the time data I tried basically the same:

 

set my_db = TL.ActiveBook.Database
Dim dataBlock as LMSTestlabAutomation.IBlock2 Set att = my_db.ElementNames(PathToThroughput) Path2 = PathToThroughput & att.item(0) Set dataBlock = my_db.GetItem(Path2)

 

With that I get in the last line a "Runtime error '13': Types mismatching". Maybe using the variable IBlock2 for the time data is the mistake. When I check my_db.ElementType(Path2)  I get "BlockStream". So it seems that the time data is in a BlockStream. However I don't know which variable type I need for that and furthermore I might also be completely lost on this.

 

So, any help is appreciated.

5 REPLIES

Re: Exporting Time Data to Excel via Testlab Automation

Siemens Genius Siemens Genius
Siemens Genius

in attach you can find a code snippet on how to export Throughput data towards Excel.

in 2 words: convert streamdata into blockdata

Re: Exporting Time Data to Excel via Testlab Automation

Thank you very much! This seems to be exactly what I was looking for.

Re: Exporting Time Data to Excel via Testlab Automation

Hello,

 

today I did some testing and sadly I don't manage to get the provided code to work. I am running it from excel as a vba-script instead of directly from visual basic. Can that influence it?

 

The problem appears to be in the Function Blockstream2Block. I can't populate the attributeMap with entries. So when I try

 

attributeMap.Add("BlockStream", dataStream) 

 

 

I get a "Error during compiling: Expected: = ". Furthermore the whole line is marked red.

 

When I then try

 

test = attributeMap.Add("BlockStream", dataStream) 

 

the line turns black again but I get "Error on compiling: Function or variable expected".

 

What am I doing wrong with the attributeMap ? Here is my altered code:

  

Function Blockstream2Block(dataStream As LMSTestLabAutomation.IData) As LMSTestLabAutomation.IBlock2
        Dim block As LMSTestLabAutomation.IBlock2
        Dim attributeMap As LMSTestLabAutomation.attributeMap
        Set block = Nothing

            ' create attribute map that describes the conversion from stream to block
            Set attributeMap = tl.CreateAttributeMap
            test = attributeMap.Add("BlockStream", dataStream)
            test = attributeMap.Add("NumberOfPoints", -1) 'Integer '-1 = All points
            test = attributeMap.Add("StartIndex", 0) 'Integer 'index
            test = attributeMap.Add("StartValue", 0) 'Double 'Time
            test = attributeMap.Add("StartValueGiven", False) 'False = begin, True= give StartIndex or StartValue

            ' conversion from datastream towards datablock
            Set block = tl.CreateObject("LmsHq::DataModelC::ExprConcat::CBlockStreamToBlock", attributeMap)

            Set Blockstream2Block = block

    End Function

 

In the main Sub I am writing:

 

Public tl as LMSTestLabAutomation.Application

Sub main()
Dim dataBlock As LMSTestLabAutomation.IBlock2
Dim datastream As LMSTestLabAutomation.IData

Set tl = New LMSTestLabAutomation.Application ...
Set dataBlock = Blockstream2Block(dataStream)
...
End sub

 

So, how can I get those entries in the attributeMap without excel complaining?

 

 

Furthermore I wanted to ask how it is possible to readout the Point id of the time data elements? By

my_db.ElementNames(PathToThroughput)

I only get some weird numbers. How can I determine from those numbers which Point id I am dealing with?

 

 

Thank you for any help on those two things.

Re: Exporting Time Data to Excel via Testlab Automation

Siemens Genius Siemens Genius
Siemens Genius

dear,

 

The syntax in vba for an attributemap is the following:

    Dim attributeMap As LMSTestLabAutomation.attributeMap
    Set attributeMap = tl.CreateAttributeMap
    attributeMap.Add "BlockStream", data

 

Reading the PointId directly from a stream is not possible, but there is a work-arround, see code snippet in attach

Re: Exporting Time Data to Excel via Testlab Automation

Thank you very much for the excellent answer. With this retrieving time data works perfectly!