Hello!
Now that I've coded successfully using the object-oriented methodology, naturally a question arises - can I export classes so that they can be shared between applications? It seems that copying and pasting a class into MyMacros / Standard library, where subs and functions are visible to all applications, does not work for classes. Can anyone share any insight on this?
Thanks in advance,
Eliot
[BASIC] Object-Oriented Programming
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
-
- Posts: 14
- Joined: Sun Feb 19, 2017 4:59 am
Re: [BASIC] Object-Oriented Programming
OpenOffice 4.1.3 on Windows 8, Leonovo laptop with 5GB ram and 1Ghz dual-core processor
Re: [BASIC] Object-Oriented Programming
Can you upload your sample code here??
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
-
- Posts: 14
- Joined: Sun Feb 19, 2017 4:59 am
Re: [BASIC] Object-Oriented Programming
This is a class that works inside a CALC application, I am looking to make it available to all CALC applications:
Code: Select all
REM ****************************************************************************
REM *** Class Cell Annotations
REM ***
REM *** Purpose: (a) Creates comments in a selected CALC cell
REM *** (b) deletes a comment from selected CALC cell
REM ***
REM *** Parent Class: PracticeTime
REM *** Child Class(es): N/A
REM ***
REM ****************************************************************************
Option Compatible
Option ClassModule
Option Explicit
REM ============================================================================
REM === Private variables
private _AnnotationText as string
REM ============================================================================
REM === Constructor & Destructor
REM ===
private sub Class_Initialize()
_AnnotationText = getCellComment()
end sub
private sub Class_Terminate()
_AnnotationText = ""
end sub
REM ============================================================================
REM === Set private variables
Public Property Let AnnotationText (ByVal pValue As String)
_AnnotationText = pValue
End Property
REM ============================================================================
REM === Get private variables
Public Property Get AnnotationText As String
AnnotationText = _AnnotationText
End Property
REM ============================================================================
REM === Public Methods
REM ===
REM ----------------------------------------------------------------------
REM --- Set text, shape, transparency and color of _Annotation (comment)
REM --- for a selected cell
REM --- Project# P002m
REM ---
public Sub setCellComment
dim oDoc,oSheet,oCell,oCellAddr,oAnnotations,_
oAnnotation,oAnnotationShape as object
dim lenComment,widthBox as integer
oDoc = ThisComponent
oSheet= oDoc.getcurrentcontroller.activesheet
oCell = oDoc.getCurrentSelection
lenComment = len( _AnnotationText )
if lenComment > 0 then
select case lenComment
case > 501:
widthBox = 12000
case 251 to 500:
widthBox = 10000
case 101 to 250:
widthBox = 8000
case 51 to 100:
widthBox = 6000
case 0 to 50:
widthBox = 4000
end select
oCellAddr = oCell.getCellAddress
oAnnotations = oSheet.getAnnotations
'/Create a new _Annotation to the active cell
oAnnotations.insertNew(oCellAddr, _AnnotationText)
'/Get the newly created _Annotation for modify properties
oAnnotation = oCell.getAnnotation
'/Set it "allways visible":
oAnnotation.setIsVisible false
'/Set color, transparence, fill style, inner margin
oAnnotationShape = oAnnotation.getAnnotationShape
oAnnotationShape.FillBackground = True
oAnnotationShape.FillColor = RGB(251, 246, 99)
oAnnotationShape.FillStyle = 1 '(0: nothing; 1: solid color; 2: gradient; 3: lined)
oAnnotationShape.FillTransparence = 15
oAnnotationShape.TextLeftDistance = 200
oAnnotationShape.TextLowerDistance = 200
oAnnotationShape.TextRightDistance = 200
oAnnotationShape.TextUpperDistance = 200
'/Set size of the _Annotation
Dim aSize As New com.sun.star.awt.Size
asize.Height = 1000
asize.Width = widthBox
oAnnotationShape.Size = asize
oAnnotationShape.SizeProtect = False
'/Set absolute position of the _Annotation
'Dim apoint As New com.sun.star.awt.Point
'apoint.x = 1000
'apoint.y = 1000
'oAnnotationShape.setPosition apoint
else
deleteComments
end if
End Sub
REM ============================================================================
REM === Private Methods
REM ===
REM ----------------------------------------------------------------------
REM --- Read the _Annotation from selected cell
REM ---
private function getCellComment()
getCellComment = ThisComponent.getCurrentSelection().getAnnotation().string
end function
private sub deleteComments
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Flags"
args1(0).Value = "N"
dispatcher.executeDispatch(document, ".uno:Delete", "", 0, args1())
end sub
OpenOffice 4.1.3 on Windows 8, Leonovo laptop with 5GB ram and 1Ghz dual-core processor
Re: [BASIC] Object-Oriented Programming
If you mean you want the class instance to be available from another library - you can put a function in a neighbouring module in the library where the class module is. Something like:
function getClassModuleInstance()
dim classinstance as new yourclassname
getClassModuleInstance = classinstance
end function
then you can call it from code in another library with:
classinstance= getClassModuleInstance()
(this is already asked/discussed earlier in this thread)
function getClassModuleInstance()
dim classinstance as new yourclassname
getClassModuleInstance = classinstance
end function
then you can call it from code in another library with:
classinstance= getClassModuleInstance()
(this is already asked/discussed earlier in this thread)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)