PDA

Ver la Versión Completa : [Sintaxis] Convertir LibreOffice Basic a COBOL¿?


Xavier
23 de agosto de 2021, 13:47
Buenos días. Alguien sabría "traducir" esta instrucción (marcada con --->) hecha con Basic de LibreOffice a instrucciones COBOL?:

Sub AbriendoDocumentos4()
Dim sRuta As String
---> Dim mOpciones(0) As New "com.sun.star.beans.PropertyValue"
Dim oDoc As Object

mOpciones(0).Name = "AsTemplate"
mOpciones(0).Value = True

sRuta = ConvertToUrl( "/home/Mi archivo de Writer.odt" )
oDoc = StarDesktop.loadComponentFromURL( sRuta, "_blank", 0, mOpciones() )

End Sub

Agradecería cualquier ayuda. Estoy intentando pasar mis aplicaciones hechas para acceder a Word a poder hacerlo con LibreOffice Writer

Kuk
23 de agosto de 2021, 16:07
@Xavier, intenta a ver:


ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TXT PIC X(50).
01 mOpciones OBJECT REFERENCE COM.
PROCEDURE DIVISION.

MOVE "com.sun.star.beans.PropertyValue" TO TXT
INVOKE COM "CREATE-OBJECT" USING TXT RETURNING mOpciones

INVOKE mOpciones "set-Name" USING "AsTemplate"
INVOKE mOpciones "set-Value" USING -1 *>True




Y échale un ojo a este post: [Aporte] Uso del ChartControl de Codejock - COBOL Foro (https://www.cobolforo.es/showthread.php?t=140&p=613)

Xavier
24 de agosto de 2021, 10:36
Gracias Kuk, ya había intentado definir así la variable
01 ServProperty PIC X(32) VALUE "com.sun.star.beans.PropertyValue".
01 objArgs OBJECT REFERENCE COM.

Pero, al trazar el programa y ejecutar la instrucción:
"INVOKE COM "Create-Object" USING ServProperty RETURNING objArgs

Me da el siguiente error: "Exception ocurrence(Exception object)

Voy a echar una ojeada al "Aporte" que me has pasado



Utiliza las etiquetas de resalto de sintaxis (los botones, Cobol, SQL etc en el editor) ;)

Kuk
24 de agosto de 2021, 12:41
@Xavier, habría que sacar la descripción del error más detallada.

Aquí tienes un ejemplo de cómo declarar las excepciones en DECLARATIVES: [Aporte] Exportar CmListview en Excel - COBOL Foro (https://www.cobolforo.es/showthread.php?t=50)

También échale un ojo a esto: [Sintaxis] Como descifrar valores de COM-EXCEPTION - COBOL Foro (https://www.cobolforo.es/showthread.php?t=104&p=419)

fastpho
24 de agosto de 2021, 17:28
@Xavier, Buscando en la web encontre dos ejemplos de OpenOffice en Net Express , creo que funcionan habria que convertirlos a powercobol
Ejemplo 1

$set ooctrl(+P)
IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.

class-control.
OServManager is class "$OLE$com.sun.star.ServiceManager"
oleSafeArray is class "olesafea" OLE SafeArray class
.

DATA DIVISION.
WORKING-STORAGE SECTION.

copy mfole.cpy.


*---SafeArray dimension structure SafeArrayBound
* celements is the total number of elements
* lBound is the lower boundary (usually 0)
01 tagSafeArrayBound is typedef.
05 celements usage ULONG.
05 llbound usage LONG.
01 SafeArrayBound is typedef usage tagSafeArrayBound.
01 saBound SafeArrayBound.


01 ServManager object reference.
01 StarDesktop object reference.
01 aDoc object reference.
01 atext object reference.

01 Group1SafeArray object reference.

01 theVarType VARTYPE.

01 cDims UINT.

*-----------------------------------------------------------------
PROCEDURE DIVISION.

Start-Up. # Start-Up
*--- create the document
perform CreateDocument-Stup.

*--- fill the document with some text
perform FillDocument-Stup.

exit program.
stop run.

*-----------------------------------------------------------------
CreateDocument-Stup. # CreateDocument-Stup
*---
invoke OServManager "new" returning ServManager

*---
invoke ServManager "createInstance"
using "com.sun.star.frame.Desktop"
returning StarDesktop.

*--- olesafearray
move VT-VARIANT to thevarType.
move 1 to cDims.
move 0 to cElements OF saBound.
move 0 to llBound OF saBound.
invoke olesafearray "new" using by value thevarType
by value cDims
by reference saBound
returning Group1SafeArray.

*--- loadComponentFromURL
invoke StarDesktop "loadComponentFromURL"
using "private:factory/swriter" change 'swriter' with 'scalc' to call openOffice Calc
"_blank"
"0"
Group1SafeArray
returning aDoc.

*-----------------------------------------------------------------
FillDocument-Stup. # FillDocument-Stup
invoke aDoc "GetText" returning aText. remove this line if you call 'Calc'
invoke aText "SetString" using "Hello World". remove this line if you call 'Calc'

*-----------------------------------------------------------------

Ejemplo 2 :

$set sourceformat(variable)
$set ooctrl( P)
IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.

class-control.
OServManager is class "$OLE$com.sun.star.ServiceManager"
oleSafeArray is class "olesafea" *> OLE SafeArray class
olesup is class "olesup"
OLEVariant is class "olevar"
olebase is class "olebase"
.

DATA DIVISION.
WORKING-STORAGE SECTION.

copy mfole.cpy.

copy olesafea.cpy. *> SafeArray records

01 theSafeArrayObj object reference.

01 saBound SAFEARRAYBOUND.

01 ServManager object reference.
01 StarDesktop object reference.
01 aDoc object reference.
01 aSheets object reference.
01 aSheet object reference.
01 aCell object reference.
01 aTempObj object reference.
01 oPropertyValue object reference.
01 hResult pic 9(9) comp-5.
01 iIndex pic 9(9) comp-5 value 0.
PROCEDURE DIVISION.

invoke OServManager "new" returning ServManager

invoke ServManager "createInstance" using "com.sun.star.frame.Desktop" returning StarDeskto

move 0 to llBound of saBound
move 1 to cElements of saBound
invoke olesafearray "new" using
by value VT-VARIANT
by value 1 *> Single dimension
by reference saBound *> Dimension boundaries
returning theSafeArrayObj

invoke StarDesktop "loadComponentFromURL" using
by reference "private:factory/scalc"
by reference "_blank"
by value 0
by reference theSafeArrayObj
returning aDoc

invoke aDoc "getSheets" returning aSheets

invoke olesup "setDispatchType" using by value 0 *> value 0 = next message forced to invoke
invoke aSheets "getByName" using by reference "Sheet1" returning aSheet

invoke olesup "setDispatchType" using by value 0 *> value 0 = next message forced to invoke
invoke aSheet "getCellByPosition" using by value 0, by value 0 returning aCell
invoke aCell "SetString" using "Hello World"

invoke ServManager "Bridge_GetStruct" using "com.sun.star.beans.PropertyValue" returning oP

invoke olesup "setDispatchType" using by value 1 *> value 1 = next message forced to invoke
invoke oPropertyValue "Name" using z"FilterName"

invoke olesup "setDispatchType" using by value 1 *> value 1 = next message forced to invoke
invoke oPropertyValue "Value" using z"MS Excel 97"
invoke theSafeArrayObj "putOLEObject"
using Iindex
by value oPropertyValue
returning hResult
end-invoke.
invoke aDoc "storeAsURL" using
by reference z"file:///C:/cobol/calctstx.xls"
by reference theSafeArrayObj

*> Finalize all objects
invoke aCell "finalize" returning aCell
invoke aSheet "finalize" returning aSheet
invoke aSheets "finalize" returning aSheets

invoke aDoc "Close" using by value -1
invoke aDoc "Finalize" returning aDoc
invoke StarDesktop "Finalize" returning StarDesktop
invoke ServManager "Finalize" returning ServManager

goback.

Saludos

Xavier
25 de agosto de 2021, 11:22
Hola @Kuk, ya hago uso de los controles para obtener una descripción más detallada del error, pero no me saca nada, solo un código de error, que lo he buscado por internet y no he conseguido ningún resultado
Esto es lo que me sale del error:

Error Type: 1
wCode: +0000
SCode: -147352571
SCode-Text:
Error Descr:

---------- Post añadido : 11:22 ---------- Post anterior : 11:02 ----------

Hola @fastpho, me parece muy interesante tu aporte. Voy a trabajar en ello y ya os digo algo

Kuk
25 de agosto de 2021, 12:52
@Xavier, creo recordar que había que hacer llamadas adicionales para sacar la descripción del error.