I have a question regarding TM1 API when used in Visual Basic 2008 Express Edition.
I had a working piece of code to log in, which works perfectly in Excel VBA (Excel 2003).
My TM1 server runs as a service, to which I connect. It's all locally on my laptop.
Below is the code that works up until the function TM1SystemServerConnect. Then my .exe file crashes.
The arguments to TM1SystemServerConnect are all nice Long variables.
I also copied the module with TM1 API functions.
Anyone has a clue? Thanks a lot in advance!
Code: Select all
Module TM1_main
Public hUser As Long
Public pGeneral As Long
Public voDatabase As Long
Public hServer As Long
Public vServerName As Long
Public vClientName As Long
Public vClientPassword As Long
Dim strMachine As String
<VBFixedString(75)> Dim strTM1server As String
<VBFixedString(75)> Dim strUser As String
<VBFixedString(75)> Dim strPassword As String
<VBFixedString(75)> Dim sElementName As String
Public Sub Update_TM1()
Dim str As String
'connect to TM1
str = Connect()
MessageBox.Show(str)
End Sub
Private Function Connect() As String
'--------------------------------------------------------------------------------
'CONSTANTS
strMachine = "wigipc"
strTM1server = "bv"
strUser = "wim"
strPassword = "blahblahblah"
'--------------------------------------------------------------------------------
' initialize the API
TM1APIInitialize()
hUser = TM1SystemOpen()
'Set the Admin Host Server Name
TM1SystemAdminHostSet(hUser, strMachine)
'Create a Pool Handle
pGeneral = TM1ValPoolCreate(hUser)
'Establish Login information
vServerName = TM1ValString(pGeneral, strTM1server.Trim, 0)
vClientName = TM1ValString(pGeneral, strUser.Trim, 0)
vClientPassword = TM1ValString(pGeneral, strPassword.Trim, 0)
'Log in to the TM1 Server
hServer = TM1SystemServerConnect(pGeneral, vServerName, vClientName, vClientPassword)
'''ERROR ==> CRASH!
'Was login succesful?
If TM1ValType(hUser, hServer) = TM1ValTypeError() Then
Connect = "The server handle is an error code." & vbCrLf & "Please verify TM1 Servername, User and Password"
Else
Connect = "Connection succesful"
End If
End Function
End Module