|
Users ask if it is possible to create a cub file for later use without having to add DynamiCube to a projects form. The answer is yes. One way to approach this situation is to add a project reference to DynamiCube, and create a DynamiCube object with events.
Note: If you are copying and pasting the code below into your own application you will need to included a project reference to DynamiCube 3. Furthermore, when creating a cub file without a DynamiCube added to a project form, some of DynamiCubes events will not fire because they require DynamiCube to be placed visually on a form.
Option Explicit
...
'Create a DynamiCube object with events.
Private WithEvents dc As DynamiCubeLib.DCube
'Save the cub file.
Private Sub Command1_Click()
dc.Save App.Path & "\myCub.cub", SOLayoutWithData
End Sub
'Setup DynamiCube and add the fields.
Private Sub Form_Load()
Dim f As DynamiCubeLib.Field
Set dc = New DynamiCubeLib.DCube
With dc
.AutoDataRefresh = False
.DCConnectType = DCCT_UNBOUND
Set f = .Fields.Add("Row1", "Row1", DCRow)
Set f = .Fields.Add("Col1", "Col1",DCColumn)
Set f = .Fields.Add("Data1", "Data1",DCData)
.RefreshData
.AutoDataRefresh = True
End With
End Sub
'Add data to DynamiCube.
Private Sub dc_FetchData()
dc.AddRowEx Array("Row1", "Col1", 100)
End Sub
The attached sample demonstrates the use of the code above to create a cub file programmatically using an unbound approach. Please feel free to use any of the code found in this article as a building block to providing this functionality in your application.
If you have any questions or need assistance, please feel free to submit a support request.
Applies To: DynamiCube 3.0
|