Connecting to the IBM Cognos TM1 API in Microsoft Visual Basic
Every IBM® Cognos® TM1® API application written in Microsoft Visual Basic must call the following
functions, in a specific order, to initialize a server session.
This is the function order:
Private Sub Form_Load()
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
'
' Each Microsoft Visual Basic application begins by calling TM1APIInitialize,
' TM1SystemAdminServerHostSet, and TM1SystemServerConnect.
'
TM1APIInitialize
hUser = TM1SystemOpen()
TM1SystemAdminHostSet hUser, "rjordon"
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)
'
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, "apple", vStringLength)
vServerName = TM1ValString(pPoolHandle, "sdata", vStringLength)
vServerHandle = TM1SystemServerConnect(pPoolHandle, _
vServerName, vUserName, vPassword)
'
' 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