Creating mathematic variables including formulars (Counter)

Creating mathematic variables including formulars (Counter)

This sample shows how to create an statistic counter (mathematic) on a variable:
VBA Code:

Public Sub CreateMatheVariable()
Dim obDriver As Driver
Dim obVarType As VarType
Dim nChannelType As Integer
Dim obVar As Variable

'create an Object of the Mathematic driver (Driver identification)
Set obDriver = MyWorkspace.ActiveDocument.Drivers.Item("Driver for Mathematics variable")
Set obVarType = MyWorkspace.ActiveDocument.VarTypes.Item("LREAL")
nChannelType = tpVirtuellOnlBerechnen 'this is equal to: obKanaltyp = 17


MyWorkspace.ActiveDocument.Variables.DeleteVar ("MyMatheVar")

Set obVar = MyWorkspace.ActiveDocument.Variables.CreateVar("MyMatheVar", obDriver, nChannelType, obVarType)

'add Source Variable (i.e. Boolean from Internal driver - has to exist already)
obVar.CreateDynProperty ("MathInfo[0].SourceVars")
obVar.DynProperties("MathInfo[0].SourceVars[0].Title") = "MyMatheSourceVar"

'define type of formular (521 = Statistik)
obVar.DynProperties("MathInfo[0].Type") = 521

'insert formular
obVar.DynProperties("MathInfo[0].Formula") = "COUNT(X01)"

'for opening the configuration dialog: with ""
'obVar.DynProperties("MathInfo[0].MathInfo") = ""

'for fix settings do it with the export string (achieved from .xml export)
obVar.DynProperties("MathInfo[0].MathInfo") = "09028800000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
End Sub


This is a migrated post! Originally posted on 12.06.2008 by user herberto. Please be aware that information can be outdated.