Working with FlexPro Project Databases
FlexPro stores all objects in a project database. You can apply a hierarchical structure to this project database by creating folders. Thus, a FlexPro project database resembles a hard disk on your computer. Instead of files on the hard drive, a FlexPro project database contains data sets, formulas, presentation objects, worksheets and documents that you need for your analysis. Just like on a hard drive, you can build up a hierarchy of folders in a FlexPro project database to organize your FlexPro objects.
Creating a Project Database
FlexPro can open multiple databases at once that are then stored in the Databases collection. To create a new, empty database, use the Add method of the Databases collection. The Add method provides the newly created database in such a way that you can assign it to a variable for later use:
Dim Doc As Database
Set Doc = Databases.Add
Opening a Database
Use the Open method of the Databases collection to open a database stored in a file.
Dim Doc As Database
Set Doc = Databases.Open("C:\Databases\MyDatabase.fpd", fpOpenModeBackup)
Saving a Database
If the database is new and has not been saved yet, use the SaveAs method. The second argument determines how the database is to be saved.
Doc.SaveAs "C:\Databases\MyDatabase.fpd", fpSaveModeOneFile
Use the Save method to save a database that has already been opened as a file and has been saved at least once before.
Doc.Save
Use the Save method of the Databases collection to save all databases that are currently open. For those databases that do not have a file name yet, a dialog box appears, in which you can specify the name.
Databases.Save
Closing a Database
You can close an individual database using its Close method.
Doc.Close fpSaveChanges
Alternatively, you can close all databases that are currently open.
Databases.Close fpPromptToSaveChanges
Accessing Databases
To access a database in the Databases collection, use the path name or the name that is displayed in FlexPro's main window.
Set Doc = Databases("C:\Databases\MyDatabase.fpd")
Use the ActiveDatabase method of the Application object to access the currently active database.
ActiveDatabase.Close
Creating Objects and Folders
Use the Add method of the Folder object to create objects and folders in the database. Use the RootFolder property of the Database object to access the root folder.
Dim Fld As Folder
Set Fld = ActiveDatabase.RootFolder.Add("Folder", fpObjectTypeFolder)
The Add method can also add other objects, returning the new object as the result.
With Fld.Add("Series", fpObjectTypeFormula)
.Formula = "(100, 0.0, 0.1)"
End With
Accessing Objects
To access an object in a folder, use the Object method of the folder. You can specify the object name and object type or just the name with the extension related to the specific type.
ActiveDatabase.RootFolder.Object("Diagram", fpObjectTypeDiagram2D) _
.Comments = "Measurement 1"
or
ActiveDatabase.RootFolder.Object("Diagram.2D").Comments = "Measurement 1"
Using the Parent property, which is available to every FlexPro object, you can access the object (usually a folder) that contains the object. The following example accesses the comment added to a folder containing the data set that has been assigned to the "Dataset" object variable.
Dataset.Parent.Comments = "Measurement 1"
Searching the Database for Objects
Use the Objects method of the Folder object to search for objects. Several options are available.
The following example finds all data set objects that have names beginning with "sig".
Dim Objects
Set Objects = ActiveDatabase.RootFolder.Objects("^sig*\.dat$")
The regular expression is structured as follows:
Sequence |
Meaning |
---|---|
"^sig" |
Specifies that the object name must start with "sig". |
".*" |
Represents a string of any length, consisting of any characters. |
"\.dat$" |
Specifies that the object name must end in ".dat", i.e. that the object must be a data set. |
The following example finds a dataset object called "Signal" and a 2D diagram called "Plot".
Dim Objects
Set Objects = ActiveDatabase.RootFolder.Objects("Signal", "Plot.2d")
The following example finds all objects in which the value of the Origin property is "Measurement 1".
Dim Constraints As New SearchConstraints
With Constraints.Add
.SearchItem = fpSearchItemOrigin
.CompareOperation = fpSearchCompareOpTextIs
.SearchValue = "Measurement 1"
End With
Dim Objects
Set Objects = ActiveDatabase.RootFolder.Objects(Constraints)
Use the Objects method of the Database object to access objects in different folders simultaneously. The following example deletes two objects.
ActiveDatabase.Objects(Array("\Diagram.2d", _
"\Measurement1\Signal")).Delete
Use the Search method of the Folder object to search through all or parts of the database for objects. The following example searches for all data sets of which the maximum value is larger than 10 and moves these data sets to the "Data Folder" folder.
Dim Constraints As New SearchConstraints
With Constraints.Add
.SearchItem = fpSearchItemObjectType
.CompareOperation = fpSearchCompareOpObjectTypeIsKindOf
.SearchValue = fpObjectTypeDataSet
End With
With Constraints.Add
.SearchItem = fpSearchItemMaximum
.CompareOperation = fpSearchCompareOpValueGreater
.SearchValue = 10#
End With
ActiveDatabase.RootFolder.Search(True, Constraints). _
MoveTo ActiveDatabase.Object("\Data Folder.FLD")