WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OpenOffice

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

OpenOffice Constant Enumeration

 Keywords: OpenOffice Constant Enumeration LibreOffice

;Winbatch - OpenOffice - Quick Kludge to get consant enum value
;                        for use in WB script
;Stan Littlefield April 18, 2010
;////////////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////////////
;RUNNING THE SCRIPT
;A test OO constant is supplied and you can fill in the askline()
;with your own to test. Script opens a blank calc workbook, inserts a udf in the
;macro area, returns the value quits and erases the temp workbook
;////////////////////////////////////////////////////////////////////////////////////
GoSub udfs
IntControl(73,1,0,0,0)

cFile=DirScript():"temp.ods"
If FileExist(cFile) Then FileDelete(cFile)

;this is a default which should return a value of 3
cEnum="com.sun.star.sheet.Border.LEFT"

;comment the above and test by uncommenting the next line
;cEnum="com.sun.star.sheet.Border.CENTER"
;it should popup a star basic error dialog, then return a value of 0 - so
;hopefully if you fat-finger an enum lookup the script won't hang
;and leave open processes.


cEnum=AskLine("OpenOffice Constant Enumeration", "Please Enter or Paste in a Valid OO Constant",cEnum, 0)


oSM=0
oDesk=0
oDoc=0
oSM = CreateObject("com.sun.star.ServiceManager")
oDesk= oSM.createInstance("com.sun.star.frame.Desktop")
aBlank = ArrDimension(1)
aBlank[0]=makeprop(oSM,"","")
oDoc = oDesk.loadComponentFromURL( "private:factory/scalc", "_hidden", 0, aBlank )
Controller = oDoc.CurrentController
Frame = Controller.Frame
ContainerWin = Frame.ContainerWindow
ContainerWin.Visible = @FALSE
cURL = StrCat("file:///",StrReplace(cFile,"\","/"))
oDoc.storeAsURL( cURL, aBlank )
cCode="REM  *****  BASIC  *****":@CRLF
cCode=cCode:"Option Explicit":@CRLF
cCode=cCode:"":@CRLF
cCode=cCode:"Sub Main":@CRLF
cCode=cCode:"":@CRLF
cCode=cCode:"End Sub":@CRLF
cCode=cCode:"":@CRLF
cCode=cCode:"Function GetEnum()":@CRLF
cCode=cCode:"  GetEnum = ":cEnum:@CRLF
cCode=cCode:"End Function":@CRLF


;now insert module code
cModule = "Module1"
oLibrary = oDoc.BasicLibraries.GetByName("Standard")
oLibrary.InsertByName(cModule, cCode)
oSheet = oDoc.getSheets().getByIndex( 0 )
cFormula = "=GetEnum()"
oSheet.getCellByPosition( 0, 0 ).setFormula( cFormula )
cVar=oSheet.getCellRangeByName( "A1" ).Value
If StrIndex(cVar,".",0,@FWDSCAN)>0 Then cVar=ItemExtract(1,cVar,".")
retval=cEnum:"=":cVar
retval="":retval
oDoc.dispose()
oSM=0
oDesk=0
oDoc=0
If FileExist(cFile) Then FileDelete(cFile)
ClipPut("")
ClipPut(retval)
Message("",retval:@CRLF:"has been placed in the clipboard")

Exit

:WBERRORHANDLER
ErrorProcessing(1,1,0,0)
oSM=0
oDesk=0
oDoc=0
Exit


:udfs
#DefineSubRoutine ErrorProcessing(deleteIni,showerr,logfile,Err_Array)
If VarType(Err_Array) ==256
   WbError = Err_Array[0]
   wberrorhandlerline = Err_Array[1]
   wberrorhandleroffset = Err_Array[2]
   wberrorhandlerassignment = Err_Array[3]
   wberrorhandlerfile = Err_Array[4]
   wberrortextstring = Err_Array[5]
   wberroradditionalinfo = Err_Array[6]
   wberrorinsegment = Err_Array[7]
Else
   WbError = LastError()
EndIf
WbTextcode = WbError
If WbError==1668||WbError==2669||WbError==3670
   WbError = ItemExtract(1,IntControl(34,-1,0,0,0),":")
   WbTextcode = -1
EndIf
WbErrorString = IntControl(34,WbTextcode,0,0,0)
WbErrorDateTime = TimeYmdHms()
If deleteIni
   WbErrorFile = StrCat(ShortCutDir( 'AppData', 0, 0 ),'\WinBatch\Settings\')
   If ! DirExist(WbErrorFile) Then WbErrorFile = DirWindows(0)
   WbErrorFile = StrCat(WbErrorFile,"WWWBATCH.INI")
   FileDelete(WbErrorFile)
   IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorValue"   ,WbError                 ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorString"  ,WbErrorString           ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptLine"   ,WbErrorHandlerLine      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset    ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarInSegment" ,WbErrorInSegment,WbErrorFile)
   IniWritePvt("","","",WbErrorFile)
EndIf
WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error# [",WbError,"]",@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"[Extended Information] ",wberroradditionalinfo,@CRLF,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"On Line:",@CRLF,WbErrorHandlerLine,@CRLF)
;WbErrorMsgText = StrCat(WbErrorMsgText,"Offset: ",WbErrorHandlerOffset,@CRLF)
If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN"
WbErrorMsgText = StrCat(WbErrorMsgText,"Assignment/Variable: ",WbErrorHandlerAssignment,@CRLF)
If (WbErrorInSegment>"") Then WbErrorMsgText = StrCat(WbErrorMsgText,"In UDF/UDS: ",WbErrorInSegment,@CRLF)
If logfile
   cSep = StrCat(StrFill("=",50),@CRLF)
   cLogFile = StrCat(DirScript(),"log.err")
   If ! FileExist(cLogFile) Then FilePut(cLogFile,StrCat("Error Log",@CRLF,cSep))
   FilePut(cLogFile,StrCat(FileGet(cLogFile),WbErrorMsgText,cSep))
   Display(2,"An Error Occured",StrCat("written to ",cLogFile))
Else
   If showerr
      WbErrorMsgText = StrCat(WbErrorMsgText,"[THIS ERROR NOT WRITTEN TO LOG FILE]",@CRLF)
      Message("An Error Was Encountered",WbErrorMsgText)
   EndIf
EndIf
Return(1)
#EndSubRoutine

#DefineFunction makeProp(oSM,cName,uValue)
oStruct = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oStruct.Name = cName
oStruct.Value = uValue
Return(oStruct)
#EndFunction


Return

Article ID:   W18158
Filename:   OpenOffice Constant Enumeration.txt
File Created: 2011:07:11:08:54:32
Last Updated: 2011:07:11:08:54:32