The TM1 API - VBA
Posted: Mon Apr 27, 2009 3:48 am
Has anyone found it very hard to debug code that makes use of the API?
Has anyone discovered that the Visual Basic section of the API in the help file seems to be a copied+edited version of the C section with a lot of inconsistencies (eg. code that works in C and not in VBA)?
Here's my current trouble: I'm simply trying to grab data out of one cell:
Cube: grid
Dimension1: x Element: 0
Dimension2: y Element: 0
The problem arises towards the end as I check the result of this call with TM1ValType and find that it returns 6 (The error code).
TM1CubeCellValueGet(pPoolHandle, hCubeObject, elementArrayCapsule)
Sub Connect_TM1_Database()
Dim sServerName As String
Dim sUsername As String
Dim sPassword As String
Dim hUserHandle As Long
Dim pPoolHandle As Long
Dim vPassword, vServerName, vUserName As Long
Dim vStringLength As Long
Dim RetVal As String * 75
Dim hCubeObject As Long
Dim vCell As Long
Dim hDimension1 As Long
Dim hDimension2 As Long
Dim vArrayLength As Long
Dim vZero As Long
Dim vElement1 As Long
Dim vElement2 As Long
'
' Each Visual Basic application begins by calling TM1APIInitialize,
' TM1SystemAdminServerHostSet, and TM1SystemServerConnect.
'
TM1APIInitialize
hUser = TM1SystemOpen()
TM1SystemAdminHostSet hUser, ""
pPoolHandle = TM1ValPoolCreate(hUser)
'
' We have to take the strings containing the login information (such as the
' user name and password) and turn them into TM1 value capsules. First
' establish the maximum length of the string as 10 characters.
'
vStringLength = TM1ValIndex(pPoolHandle, 10)
vArrayLength = TM1ValIndex(pPoolHandle, 2)
'
' Next, use this string length to build value capsules for the
' user name, password, and TM1Server name. We can reuse the pool handle
' for these functions.
'
vUserName = TM1ValString(pPoolHandle, "admin", vStringLength)
vPassword = TM1ValString(pPoolHandle, "", vStringLength)
vServerName = TM1ValString(pPoolHandle, "utopia", vStringLength)
vServerHandle = TM1SystemServerConnect(pPoolHandle, vServerName, vUserName, vPassword)
Dim numberOfCubes As Integer
Dim CubeCount As Long
CubeCount = TM1ObjectListCountGet(pPoolHandle, vServerHandle, TM1ServerCubes())
numberOfCubes = TM1ValIndexGet(hUser, CubeCount)
Debug.Print numberOfCubes
ReDim elementArray(2) As Long
' vZero = TM1ValIndex(pPoolHandle, 0)
' Open up dimension x
hDimension1 = TM1ObjectListHandleByNameGet(pPoolHandle, vServerHandle, TM1ServerDimensions(), TM1ValString(pPoolHandle, "x", 0))
vElement1 = TM1ObjectListHandleByNameGet(pPoolHandle, hDimension1, TM1DimensionElements(), TM1ValString(pPoolHandle, "0", 0))
hDimension2 = TM1ObjectListHandleByNameGet(pPoolHandle, vServerHandle, TM1ServerDimensions(), TM1ValString(pPoolHandle, "y", 0))
vElement2 = TM1ObjectListHandleByNameGet(pPoolHandle, hDimension2, TM1DimensionElements(), TM1ValString(pPoolHandle, "0", 0))
Dim retval2 As String * 10
Dim vVar2 As Variant
elementArray(1) = vElement1
elementArray(2) = vElement2
'
' vVar2 = TM1ObjectPropertyGet(pPoolHandle, vElement1, TM1ObjectName())
' MsgBox TM1ValType(hUser, vVar2)
' Call TM1ValStringGet_VB(hUser, vVar2, retval2, 1)
' MsgBox retval2 & "."
Dim elementArrayCapsule As Long
elementArrayCapsule = TM1ValArray(pPoolHandle, elementArray, 2)
hCubeObject = TM1ObjectListHandleByNameGet(pPoolHandle, vServerHandle, TM1ServerCubes(), TM1ValString(pPoolHandle, "grid", 0))
Dim something As Variant
something = TM1CubeCellValueGet(pPoolHandle, hCubeObject, elementArrayCapsule)
MsgBox TM1ValType(hUser, something)
'
' To log out and disconnect from the API, you must
' call TM1SystemServerDisconnect, TM1SystemClose, then TM1APIFinalize.
'
' In addition, best practice dictates that all TM1 Value Pools used
' in your program be destroyed by calling TM1ValPoolDestroy().
'
vResult = TM1SystemServerDisconnect(pPoolHandle, vServerName)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Add Code to delete all TM1 Value Pools here.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TM1ValPoolDestroy (pPoolHandle)
TM1SystemClose hUser
TM1APIFinalize
End Sub
Has anyone discovered that the Visual Basic section of the API in the help file seems to be a copied+edited version of the C section with a lot of inconsistencies (eg. code that works in C and not in VBA)?
Here's my current trouble: I'm simply trying to grab data out of one cell:
Cube: grid
Dimension1: x Element: 0
Dimension2: y Element: 0
The problem arises towards the end as I check the result of this call with TM1ValType and find that it returns 6 (The error code).
TM1CubeCellValueGet(pPoolHandle, hCubeObject, elementArrayCapsule)
Sub Connect_TM1_Database()
Dim sServerName As String
Dim sUsername As String
Dim sPassword As String
Dim hUserHandle As Long
Dim pPoolHandle As Long
Dim vPassword, vServerName, vUserName As Long
Dim vStringLength As Long
Dim RetVal As String * 75
Dim hCubeObject As Long
Dim vCell As Long
Dim hDimension1 As Long
Dim hDimension2 As Long
Dim vArrayLength As Long
Dim vZero As Long
Dim vElement1 As Long
Dim vElement2 As Long
'
' Each Visual Basic application begins by calling TM1APIInitialize,
' TM1SystemAdminServerHostSet, and TM1SystemServerConnect.
'
TM1APIInitialize
hUser = TM1SystemOpen()
TM1SystemAdminHostSet hUser, ""
pPoolHandle = TM1ValPoolCreate(hUser)
'
' We have to take the strings containing the login information (such as the
' user name and password) and turn them into TM1 value capsules. First
' establish the maximum length of the string as 10 characters.
'
vStringLength = TM1ValIndex(pPoolHandle, 10)
vArrayLength = TM1ValIndex(pPoolHandle, 2)
'
' Next, use this string length to build value capsules for the
' user name, password, and TM1Server name. We can reuse the pool handle
' for these functions.
'
vUserName = TM1ValString(pPoolHandle, "admin", vStringLength)
vPassword = TM1ValString(pPoolHandle, "", vStringLength)
vServerName = TM1ValString(pPoolHandle, "utopia", vStringLength)
vServerHandle = TM1SystemServerConnect(pPoolHandle, vServerName, vUserName, vPassword)
Dim numberOfCubes As Integer
Dim CubeCount As Long
CubeCount = TM1ObjectListCountGet(pPoolHandle, vServerHandle, TM1ServerCubes())
numberOfCubes = TM1ValIndexGet(hUser, CubeCount)
Debug.Print numberOfCubes
ReDim elementArray(2) As Long
' vZero = TM1ValIndex(pPoolHandle, 0)
' Open up dimension x
hDimension1 = TM1ObjectListHandleByNameGet(pPoolHandle, vServerHandle, TM1ServerDimensions(), TM1ValString(pPoolHandle, "x", 0))
vElement1 = TM1ObjectListHandleByNameGet(pPoolHandle, hDimension1, TM1DimensionElements(), TM1ValString(pPoolHandle, "0", 0))
hDimension2 = TM1ObjectListHandleByNameGet(pPoolHandle, vServerHandle, TM1ServerDimensions(), TM1ValString(pPoolHandle, "y", 0))
vElement2 = TM1ObjectListHandleByNameGet(pPoolHandle, hDimension2, TM1DimensionElements(), TM1ValString(pPoolHandle, "0", 0))
Dim retval2 As String * 10
Dim vVar2 As Variant
elementArray(1) = vElement1
elementArray(2) = vElement2
'
' vVar2 = TM1ObjectPropertyGet(pPoolHandle, vElement1, TM1ObjectName())
' MsgBox TM1ValType(hUser, vVar2)
' Call TM1ValStringGet_VB(hUser, vVar2, retval2, 1)
' MsgBox retval2 & "."
Dim elementArrayCapsule As Long
elementArrayCapsule = TM1ValArray(pPoolHandle, elementArray, 2)
hCubeObject = TM1ObjectListHandleByNameGet(pPoolHandle, vServerHandle, TM1ServerCubes(), TM1ValString(pPoolHandle, "grid", 0))
Dim something As Variant
something = TM1CubeCellValueGet(pPoolHandle, hCubeObject, elementArrayCapsule)
MsgBox TM1ValType(hUser, something)
'
' To log out and disconnect from the API, you must
' call TM1SystemServerDisconnect, TM1SystemClose, then TM1APIFinalize.
'
' In addition, best practice dictates that all TM1 Value Pools used
' in your program be destroyed by calling TM1ValPoolDestroy().
'
vResult = TM1SystemServerDisconnect(pPoolHandle, vServerName)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Add Code to delete all TM1 Value Pools here.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TM1ValPoolDestroy (pPoolHandle)
TM1SystemClose hUser
TM1APIFinalize
End Sub