Bug 139829 - User defined function malfunction after opening Calc document
Summary: User defined function malfunction after opening Calc document
Status: RESOLVED INSUFFICIENTDATA
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.4.7.2 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-22 10:09 UTC by Jerzy Moruś
Modified: 2022-02-05 03:43 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerzy Moruś 2021-01-22 10:09:08 UTC
Description:
I have written a user function to obtain selected information about a document. Here it is:

Function DokInfo(optional info, Optional styl)
REM The function returns the document information indicated by the parameter.
REM the "info" argument must be the text:
REM "AutorO" - gives the author of the document.
REM "Utworzony" - document creation date.
REM "Zmodyfikowany" - date of last modification.
REM "AutorM" - author of the last modification.
REM "Ile" - Number of sessions with the document.
REM "Czas" - total working time on the document.
REM styl, if present, must be one of the acceptable formats
REM presentation of date and / or time given as text as in the TEXT () function
Dim oData As Object, oDoc As Object
If isMissing(info) Or isArray(info) Then DokInfo="Zły argument" : Stop 'Bad argument
If IsMissing(styl) Then styl="Standard"
oDoc=ThisComponent
On Local Error GoTo niemodyfikowany
oDoc=oDoc.DocumentProperties
info=UCase(info)
With oDoc
Select Case info
   Case "AUTORO"				' - gives the author of the document.
      DokInfo= .Author
   Case "UTWORZONY"				' - document creation date.
      oData=.CreationDate
      GoSub kiedy
   Case "ZMODYFIKOWANY"			' - date of last modification.
      oData=.ModificationDate
      GoSub kiedy
   Case "AUTORM"   				' - author of the last modification.
      DokInfo=.ModifiedBy
   Case "ILE"					' - Number of sessions with the document.
      DokInfo=.EditingCycles
   Case "CZAS"					' - total working time on the document.
      DokInfo=Format(.EditingDuration/86400,Iif(styl="Standard","[h]:mm:ss",styl))
   Case Else
      DokInfo="Zły argument"	'Bad argument
   End Select
End With
Exit Function
kiedy:
      With oData
         DokInfo=Format(DateSerial(.Year,.Month,.Day)+TimeSerial(.hours,.minutes,.seconds),styl)
      End With
Return
niemodyfikowany:
DokInfo="Dokument nie był modyfikowany" 'The document was not modified
End Function

If I save the function together with the document in the document container, it works fine.
If a function is placed in the "My Macros" container, then after loading the file in which the function was used, it does not determine the correct information. They will appear only after the file is forced to be reloaded, or after the cell with the function is forcibly moved to another place or its contents copied (e.g. to itself).

While looking for a solution to the problem, I wrote another simple function.

Test function (Optional wrs, Optional kol)
If isMissing (wrs) Then wrs = 0
If IsMissing (col) Then col = 0
test = thisComponent.Sheets (0) .GetCellByPosition (kol, wrs) .String
End function

It turns out that after loading the file, it also does not return any result if it is in the "My Macros" container and document must be reloaded for good results.
What could be the reason for this action? 

Steps to Reproduce:
1. Add the attached function (eg test) to the "Standard" library in the "My Macros" container.
2. Create a Calc document where you will apply this feature.
3. Save the document and close it.
4. Open the document again.

Actual Results:
The cell containing the function displays no value (function test) or contains false values (function DokInfo).

Expected Results:
The result of the function should be displayed. It will only appear after reloading the file.


Reproducible: Always


User Profile Reset: No



Additional Info:
Such an action appears in many colleagues on the LibreOffice forum.
Comment 1 Andreas Heinisch 2021-07-07 18:25:51 UTC
I cannot reproduce the error in:

Version: 7.3.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: 0aea0cee58fe77a9058217dfdfc3d6a02b29ee2a
CPU threads: 6; OS: Windows 10.0 Build 19042; UI render: Skia/Raster; VCL: win
Locale: en-US (de_DE); UI: en-US
Calc: CL

I tried to reproduce it in this order:
1) Inserted your macro under Module 1 under Standard Macros.
2) Createda function using your function: 

function test
	Msgbox DokInfo("Utworzony")
end function

3) Created a new Calc document
4) Execute the macro

Are these steps correct or am I missing something?
Comment 2 QA Administrators 2022-01-05 03:40:08 UTC Comment hidden (obsolete)
Comment 3 QA Administrators 2022-02-05 03:43:28 UTC
Dear Jerzy Moruś,

Please read this message in its entirety before proceeding.

Your bug report is being closed as INSUFFICIENTDATA due to inactivity and
a lack of information which is needed in order to accurately
reproduce and confirm the problem. We encourage you to retest
your bug against the latest release. If the issue is still
present in the latest stable release, we need the following
information (please ignore any that you've already provided):

a) Provide details of your system including your operating
   system and the latest version of LibreOffice that you have
   confirmed the bug to be present

b) Provide easy to reproduce steps – the simpler the better

c) Provide any test case(s) which will help us confirm the problem

d) Provide screenshots of the problem if you think it might help

e) Read all comments and provide any requested information

Once all of this is done, please set the bug back to UNCONFIRMED
and we will attempt to reproduce the issue. Please do not:

a) respond via email 

b) update the version field in the bug or any of the other details
   on the top section of our bug tracker

Warm Regards,
QA Team

MassPing-NeedInfo-FollowUp