APISDWTutorialVBA

 << Back to Quick Start Guide

Synthesis Data Warehouse (SDW) Tutorial
 * VBA
 * VB.NET

This VBA tutorial will demonstrate one approach to read data from an Excel file and extract it for the SDW. Note that this tutorial is for demonstration purposes only and does not include any exception handling. To complete this tutorial successfully, please use the sample Excel data that was provided for this exercise.

Transfer Data from an Excel File to the SDW (VBA)
1. We'll begin with the  class, which represents an SDW data collection. We'll then use the  property to specify that the data collection is for use with Weibull++.

Using the Excel file you've created for this tutorial, create a new module and start with the following code to create an SDW data collection.

VBA DataCollection RawDataSet DataCollection.ExtractedName = DataCollection.ExtractedType = RawDataSetType_Weibull

2. Next, we'll use the  class to represent a single row of data, and then use the   method to add the row to the data collection.

The following code demonstrates one way to extract a row of data from the Excel sheet. For, the code creates a new   object, and then sets its properties by using the values from row #2 of the Excel file. After the code finishes reading the row of data, it adds the object to the data collection. When the code reaches, it increases   with 1 and jumps back to the   statement, which adds another new   object, sets its properties with the data from row #3 of the Excel sheet, and adds the row to the data collection. The loop continues until  reaches the specified number of rows (MaxRow).

VBA Row RawData i Integer, MaxRow  Integer MaxRow = 20 i = 2 MaxRow Row = RawData Row.StateFS = Sheet1.Cells(i, 1) Row.StateTime = Sheet1.Cells(i,2) Row.FailureMode = Sheet1.Cells(i,3) DataCollection.AddDataRow(Row) i

3. Now that the data from the Excel sheet have been copied to the data collection, the next step is to save the data collection to the Synthesis repository.

First, connect to the Synthesis repository and then use the  method to save the data collection to the repository.

VBA MyRepository Repository MyRepository.ConnectToRepository MyRepository.DataWarehouse.SaveRawDataSet(DataCollection)

Test the Code
Let's verify whether the code can import the data successfully into the SDW.

Below is the complete code list for this example. On the Debug menu, click Start to run the application. Then verify that the data were imported by launching Weibull++, opening the SDW (Home > Synthesis > Synthesis Data Warehouse) and then selecting the new data collection. (You may need to display the StateTime, StateFS and FailureMode columns by right-clicking a column header and choosing Select Columns.)

VBA Sub Main DataCollection RawDataSet DataCollection.ExtractedName = DataCollection.ExtractedType = RawDataSetType_Weibull Row RawData i Integer, MaxRow  Integer MaxRow = 20 i = 2 MaxRow Row = RawData Row.StateFS = Sheet1.Cells(i, 1) Row.StateTime = Sheet1.Cells(i,2) Row.FailureMode = Sheet1.Cells(i,3) DataCollection.AddDataRow(Row) i   MyRepository  Repository MyRepository.ConnectToRepository MyRepository.DataWarehouse.SaveRawDataSet(DataCollection) End Sub