From: Clages on
Hi
I am using netcobol a lot with no problems
in this case i am using a OCX (to make a BI)
i have everything ready - almost 95% , but i am in troble with this
code in VB

http://developers.contourcomponents.com/?pcode=overview

How can i convert this sample in VB to netcobol (Powercobol)

tks
Clages


[Visual Basic]

Dim mi As IMicrocube
Dim slice
Set mi = ContourCubeX1.Cube.LoadMetadata("metadata.lt")
slice = mi.GetSliceNames()(0)
ContourCubeX1.BindMicrocube mi, slice, mi.GetGridNames(slice)(0)
'load data
ContourCubeX1.Cube.LoadData App.Path + "northwind.cube"
ContourCubeX1.Active = True

This example shows how to load metadata to an existing microcube.

From: Pete Dashwood on
Clages wrote:
> Hi
> I am using netcobol a lot with no problems
> in this case i am using a OCX (to make a BI)
> i have everything ready - almost 95% , but i am in troble with this
> code in VB
>
> http://developers.contourcomponents.com/?pcode=overview
>
> How can i convert this sample in VB to netcobol (Powercobol)
>
> tks
> Clages
>
>
> [Visual Basic]
>
> Dim mi As IMicrocube
> Dim slice
> Set mi = ContourCubeX1.Cube.LoadMetadata("metadata.lt")
> slice = mi.GetSliceNames()(0)
> ContourCubeX1.BindMicrocube mi, slice, mi.GetGridNames(slice)(0)
> 'load data
> ContourCubeX1.Cube.LoadData App.Path + "northwind.cube"
> ContourCubeX1.Active = True
>
> This example shows how to load metadata to an existing microcube.

Hi Carlos,

here's my contribution. Hope it helps...

I'll go through the VB commenting as I go. Please don't be offended if I
mention stuff you already know.


[Visual Basic]

Dim mi As IMicrocube

[Pete]
This is equivalent to a COBOL "object reference" and establishes a pointer
of type "IMicrocube". For the type to be recognised you must have a Class
reference to IMicrocube in the REPOSITORY. Make sure you have a REPOSITORY
reference to the *COM Class also.

01 mi OBJECT REFERENCE IMicrocube.
[/Pete]

Dim slice
[Pete]

This worries me a little because I'm not sure what the type is (I think it
defaults to "String" and later it looks as if it could be referencing an
array). Assume for now it is a string.
[/Pete]

Set mi = ContourCubeX1.Cube.LoadMetadata("metadata.lt")
[Pete]

This uses the ability of VB to get a reference some ways down a reference
hierarchy. In COBOL it will need more than one step.

The first step is to get a reference to the base object. I'm assuming you
already have an object, created with CREATE-OBJECT, which references the
cube, as "ContourCubeX1". Obviously, you have installed and registered the
OCX (COM) component.
then...

You will also need another object reference...

01 cube OBJECT REFERENCE IMicrocube.


and...

invoke ContourCubeX1 "<constructor method for cube object>"
returning cube
end-invoke

This gives a reference to the cube object that is part of ContourCubeX1.
The docs should show what methods ContourCubeX1 can invoke and there should
be a constructor for the cube. (It might be called "new" or something like
that...) Use an Object Browser on the .OCX if you don't have docs for it.

Then...
invoke cube "LoadMetadata"
using metadata-path
returning mi
end-invoke

Remember that in COBOL for COM objects you cannot pass parameters by VALUE,
so you would need to have a definition for the metadata file path:

01 metadata-path pic x(20) value "metadata.lt".

Again, I can't be sure about this without having a list of the methods and
properties available from the base object. I've assumed there is a "cube"
object that has its own constructor,but if that isn't correct you will need
to look at the objects available in the hierachy and build them along the
same principles as shown above. (Use the reference to one object to invoke
its methods to build another object that is dependent on it.) If you don't
have proper docs you could use an Object Browser on the OCX to see what it
can do. (If you are using Visual Studio, you would set a reference to the
..OCX and then IntelliSense will show you what the methods and properties
are. I don't think you can use it with NetCOBOL (it is available for
NetCOBOL for .Net))
[/Pete]

slice = mi.GetSliceNames()(0)
[Pete]

The worry here is the extra (0). It looks like an array index but in some
languages this is just an offset into a string and could be representing the
beginning of the string. I honestly don't know and I'm not a VB expert.
Perhaps someone who is can contribute more? I'm assuming it is an offset to
the beginning of the returned string (mainly because the "slice" is not
declared as an array... see above) Certainly, the method name kind of
implies there are a number of names that could be retrieved.., and the (0)
would indicate we want the first one. Need more information to be sure.

invoke mi "GetSliceNames"
returning slice
end-invoke

If this complains about parameters it is likely that the index needs to be
passed as well. Remember that in COBOL for COM objects you cannot pass
parameters by VALUE, so you would need to set a field up as a small integer
and pass the name of it. However, I think this is unlikely as it would be
inside the parentheses of the VB Method signature if it were supposed to be
passed.

(unlikely)

invoke mi "GetSliceNames"
using slice-name-index
returning slice
end-invoke
[/Pete]

ContourCubeX1.BindMicrocube mi, slice, mi.GetGridNames(slice)(0)
[Pete]

There is an already established reference to "ContourCubeX1". It now needs
to have the microcube prepared above, bound to it using its "BindMicrocube"
method. There is a problem here in that it uses the name in "slice" to
reference an array of grid names in the microcube. Although VB can do that
as part of a parameter list, COBOL can't. You need another step to obtain
the grid name and store it in a string that can be referenced as a parameter
to the BindMicrocube Method.

invoke mi "GetGridNames"
using slice
returning GridName
end-invoke

....where GridName is a pic x field.

THEN...

invoke ContourCubeX1 "BindMicrocube"
using
mi
slice
GridName
end-invoke

Again, I'm not sure of how to deal with the (0). Try and get someone with
good VB knowledge to explain what this is and what it does.
[/Pete]


'load data
ContourCubeX1.Cube.LoadData App.Path + "northwind.cube"
[Pete]

invoke cube "LoadData"
using application-path
end-invoke

Uses the cube reference we established above. Define "application-path" so
it can be referenced BY REFERENCE. (All parameters to COM objects in COBOL
must be by reference) It should have a value of something like:
"c:\myfolder\mysubfolder\northwind.cube" in this instance...
[/Pete]

ContourCubeX1.Active = True
[Pete]

invoke ContourCubeX1 "SET-Active"
using ws-true
end-invoke

You need to set a referenceable value for "True"...
01 ws-true pic s9(4) comp value -1.

In PowerCOBOL you could use a value of POW-TRUE.

[/Pete]

While I accept that this is not a definitive solution, there just isn't
enough information to provide one.

The important things to bear in mind are the principles involved. I've tried
to show above that things which are pretty simple in other OO languages,
CAN be done in COBOL, but it takes more work.

You need to break things down into steps and put the steps together.
Sometimes it takes a number of steps to achieve the same result that can be
achieved with one line of VB or C#.

If nothing else, the above should give you some more insight into solving
this problem.

Regards,

Pete.
--
"I used to write COBOL...now I can do anything."


From: Clages on
On 7 jan, 21:47, "Pete Dashwood" <dashw...(a)removethis.enternet.co.nz>
wrote:
> Clages wrote:
> > Hi
> > I am using netcobol a lot with no problems
> > in this case i am using a OCX  (to make a BI)
> > i have everything ready  - almost  95% , but i am in troble with this
> > code in VB
>
> >http://developers.contourcomponents.com/?pcode=overview
>
> > How can i  convert this sample in VB to netcobol (Powercobol)
>
> > tks
> > Clages
>
> > [Visual Basic]
>
> > Dim mi As IMicrocube
> > Dim slice
> > Set mi = ContourCubeX1.Cube.LoadMetadata("metadata.lt")
> > slice = mi.GetSliceNames()(0)
> > ContourCubeX1.BindMicrocube mi, slice, mi.GetGridNames(slice)(0)
> > 'load data
> > ContourCubeX1.Cube.LoadData App.Path + "northwind.cube"
> > ContourCubeX1.Active = True
>
> > This example shows how to load metadata to an existing microcube.
>
> Hi Carlos,
>
> here's my contribution. Hope it helps...
>
> I'll go through the VB commenting as I go. Please don't be offended if I
> mention stuff you already know.
>
> [Visual Basic]
>
> Dim mi As IMicrocube
>
> [Pete]
> This is equivalent to a COBOL "object reference" and establishes a pointer
> of type "IMicrocube". For the type to be recognised you must have a Class
> reference to IMicrocube in the REPOSITORY. Make sure you have a REPOSITORY
> reference to the *COM Class also.
>
> 01 mi OBJECT REFERENCE IMicrocube.
> [/Pete]
>
> Dim slice
> [Pete]
>
> This worries me a little because I'm not sure what the type is (I think it
> defaults to "String" and later it looks as if it could be referencing an
> array). Assume for now it is a string.
> [/Pete]
>
> Set mi = ContourCubeX1.Cube.LoadMetadata("metadata.lt")
> [Pete]
>
> This uses the ability of VB to get a reference some ways down a reference
> hierarchy. In COBOL it will need more than one step.
>
> The first step is to get a reference to the base object.  I'm assuming you
> already have an object, created with CREATE-OBJECT, which references the
> cube, as "ContourCubeX1". Obviously, you have installed and registered the
> OCX (COM) component.
> then...
>
> You will also need another object reference...
>
> 01 cube OBJECT REFERENCE IMicrocube.
>
> and...
>
>        invoke ContourCubeX1 "<constructor method for cube object>"
>                    returning cube
>        end-invoke
>
> This gives a reference to the cube object that is part of ContourCubeX1.
> The docs should show what methods ContourCubeX1 can invoke and there should
> be a constructor for the cube. (It might be called "new" or something like
> that...) Use an Object Browser on the .OCX if you don't have docs for it.
>
> Then...
>        invoke cube "LoadMetadata"
>                   using metadata-path
>                   returning mi
>        end-invoke
>
> Remember that in COBOL for COM objects you cannot pass parameters by VALUE,
> so you would need to have a definition for the metadata file path:
>
> 01   metadata-path pic x(20) value "metadata.lt".
>
> Again, I can't be sure about this without having a list of the methods and
> properties available from the base object. I've assumed there is a "cube"
> object that has its own constructor,but if that isn't correct you will need
> to look at the objects available in the hierachy and build them along the
> same principles as shown above. (Use the reference to one object to invoke
> its methods to build another object that is dependent on it.) If you don't
> have proper docs you could use an Object Browser on the OCX to see what it
> can do. (If you are using Visual Studio, you would set a reference to the
> .OCX and then IntelliSense will show you what the methods and properties
> are. I don't think you can use it with NetCOBOL (it is available for
> NetCOBOL for .Net))
> [/Pete]
>
> slice = mi.GetSliceNames()(0)
> [Pete]
>
> The worry here is the extra (0). It looks like an array index  but in some
> languages this is just an offset into a string and could be representing the
> beginning of the string. I honestly don't know and I'm not a VB expert.
> Perhaps someone who is can contribute more? I'm assuming it is an offset to
> the beginning of the returned string (mainly because the "slice" is not
> declared as an array... see above) Certainly, the method name kind of
> implies there are a number of names that could be retrieved.., and the (0)
> would indicate we want the first one. Need more information to be sure.
>
> invoke mi "GetSliceNames"
>            returning slice
> end-invoke
>
> If this complains about parameters it is likely that the index needs to be
> passed as well. Remember that in COBOL for COM objects you cannot pass
> parameters by VALUE, so you would need to set a field up as a small integer
> and pass the name of it. However, I think this is unlikely as it would be
> inside the parentheses of the VB Method signature if it were supposed to be
> passed.
>
> (unlikely)
>
> invoke mi "GetSliceNames"
>           using slice-name-index
>            returning slice
> end-invoke
>  [/Pete]
>
> ContourCubeX1.BindMicrocube mi, slice, mi.GetGridNames(slice)(0)
> [Pete]
>
> There is an already established reference to "ContourCubeX1".  It now needs
> to have the microcube prepared above, bound to it using its "BindMicrocube"
> method. There is a problem here in that  it uses the name in "slice" to
> reference an array of grid names in the microcube. Although VB can do that
> as part of a parameter list, COBOL can't. You need another step to obtain
> the grid name and store it in a string that can be referenced as a parameter
> to the BindMicrocube Method.
>
> invoke mi "GetGridNames"
>             using slice
>             returning GridName
> end-invoke
>
> ...where GridName is a pic x field.
>
> THEN...
>
> invoke ContourCubeX1 "BindMicrocube"
>            using
>                  mi
>                  slice
>                  GridName
> end-invoke
>
> Again, I'm not sure of how to deal with the (0). Try and get someone with
> good VB knowledge to explain what this is and what it does.
> [/Pete]
>
> 'load data
> ContourCubeX1.Cube.LoadData App.Path + "northwind.cube"
> [Pete]
>
> invoke cube "LoadData"
>            using  application-path
> end-invoke
>
> Uses the cube reference we established above. Define "application-path" so
> it can be referenced BY REFERENCE. (All parameters to COM objects in COBOL
> must be by reference) It should have a value of something like:
> "c:\myfolder\mysubfolder\northwind.cube" in this instance...
> [/Pete]
>
> ContourCubeX1.Active = True
> [Pete]
>
> invoke ContourCubeX1 "SET-Active"
>         using ws-true
> end-invoke
>
> You need to set a referenceable value for "True"...
> 01 ws-true  pic s9(4) comp value -1.
>
> In PowerCOBOL you could use a value of  POW-TRUE.
>
> [/Pete]
>
> While I accept that this is not a definitive solution, there just isn't
> enough information to provide one.
>
> The important things to bear in mind are the principles involved. I've tried
> to show above that things which are pretty simple in  other OO languages,
> CAN be done in COBOL, but it takes more work.
>
> You need to break things down into steps and put the steps together.
> Sometimes it takes a number of steps to achieve the same result that can be
> achieved with one line of VB or C#.
>
> If nothing else, the above should give you some more insight into solving
> this problem.
>
> Regards,
>
> Pete.
> --
> "I used to write COBOL...now I can do anything."





Hi Peter
Tks for reply
I will try it and let the people Know if it works


By the way see below
If somebody need the Help of this Ocx I have IT

Tks again
Carlos Lages


--------------------------------------------------
Returns names of slices in the loaded microcube

[Visual Basic]
Public Function GetSliceNames ( ) As Variant

Example
[Visual Basic]

Dim sname
Dim sliceList
sliceList = myMicrocube.GetSliceNames()
For Each sname In sliceList
MsgBox "Slice " & sname
Next

Displays all slices in the microcube myMicrocube.
-------------------------------------------------