samuvk wrote:I'm trying to get the cubes's names in a server with the next code throught the APIs.
ServerInt = TM1ObjectListHandleByNameGet(hPool, hServer, Tm1PropertyList, TM1ValString(hPool, cube, 100))
My problem is that after execute this sentence I don't know how to get the names.
I think to understand that I get the result in TM1ValString(hPool, cube, 100),
Alas, you do not. That is where you PASS the name of the object TO the function.
samuvk wrote:But I don't know if this is true, or how to use the result and get the names, one by one.
For example: If for the server I have to cubes: (Cube1, cube2) My goal is to get those two names.
Thank you very much
I agree with Martin; don't use the API, his method is much simpler.
In addition to which you're using the wrong function. You'd already need to
know the names to use TM1ObjectListHandleByNameGet, and that would only be returning a handle to the object, not the name of the object.
Getting a list of cubes is actually one of the easier (

??!!) things to do in the API, but "easy" is a relative term when working with that monster.
Assuming that you already have a user handle (hUser), a handle to the server (hServer) and a handle to a value pool (hPool), you would need to do the following:
1/ Get a value capsule containing the number of cubes:
vhCubes = TM1ObjectListCountGet(hPool, hServer, TM1ServerCubes())
2/ Extract that as an integer value:
i_CubesCnt = TM1ValIndexGet(hUser, vhCubes)
Then use a loop from 1 to i_CubesCnt in which you do the following.
3/ Initialise the string that will hold the cube name. There are other ways of doing this but I do it as:
sCubeName = String$(gIC_TM1STRING_SIZE_DEFT, Chr(0))
You need to do that because the API functions won't clear the previous contents of the variable, so if you have a long cube name (say "ProfitAndLoss") followed by a short cube name (like "Stats") and don't clear the variable, you'll get "StatstAndLoss") returned when you get the second cube's name.)
(Note: gIC_TM1STRING_SIZE_DEFT is a constant that I had defined with a value of 255. Also, the variable itself was declared as a fixed length string; Dim sCubeName As String * gIC_TM1STRING_SIZE_DEFT)
4/ Get a handle to the cube by using its index, since you don't know its name. (i_CubesIdx is being used to loop through the cubes from 1 to i_CubesCnt):
hCube = TM1ObjectListHandleByIndexGet(hPool, hServer, TM1ServerCubes(), TM1ValIndex(hPool, i_CubesIdx))
5/ Get a value capsule containing the cube name from that handle:
vhCubeName = TM1ObjectPropertyGet(hPool, hCube, TM1ObjectName())
6/ Convert the contents of the value capsule to a string:
TM1ValStringGet_VB hUser, vhCubeName, sCubeName, gIC_TM1STRING_SIZE_DEFT
7/ Trim the trailing null characters from the sCubeName variable.
Then do the cleanup; destroy your pool handle, blah, blah.
And I'd also generally check the value capsules using TM1ValType at each step to ensure that they contained what you think they contained and not an error.
I'll bet Martin's method is looking pretty good about now, no?
