Bug 150281

Summary: VBA Application.CentimetersToPoints must give Double in Calc
Product: LibreOffice Reporter: Mike Kaganski <mikekaganski>
Component: BASICAssignee: Baole Fang <baole.fang>
Status: RESOLVED FIXED    
Severity: normal CC: 79045_79045, himajin100000, mentoring
Priority: medium Keywords: difficultyBeginner, easyHack, skillCpp
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard: target:7.6.0
Crash report or crash signature: Regression By:
Bug Depends on:    
Bug Blocks: 108908    

Description Mike Kaganski 2022-08-06 06:59:32 UTC
In both Word and Excel, there are Application.CentimetersToPoints. However, they return different types: Word's return Single [1], while Excel's returns Double [2]. Note that the argument types they take are also different.

Create a text document in Writer; add a macro *to it* (Application object seems to only be available from document modules):


Option VBASupport 1

Sub Main
  msgbox TypeName(Application.CentimetersToPoints(1))
End Sub

The result is the expected "Single".

Now repeat the process with a Calc document. The same macro must give "Double", but gives the same "Single".

The common method is declared in ooo::vba::XApplicationBase [3], and defined in VbaApplicationBase [4].

Interesting thing is, that for Word VBA Application, this function is *also* declared in XApplication [5], and overloaded in SwVbaApplication [6], together with other conversion function absent from Excel's Application object.

I suspect that initially, it was assumed that same-name methods in both VBA Application objects were the same, hence it was declared in the common ancestor class. However, the methods are different, so it makes sense to remove it from the ancestor, and declare/define in Excel VBA Application compatibility class (ScVbaApplication).

[1] https://docs.microsoft.com/en-us/office/vba/api/Word.Application.CentimetersToPoints
[2] https://docs.microsoft.com/en-us/office/vba/api/Excel.Application.CentimetersToPoints
[3] https://opengrok.libreoffice.org/xref/core/oovbaapi/ooo/vba/XApplicationBase.idl?r=5687eba4#40
[4] https://opengrok.libreoffice.org/xref/core/vbahelper/source/vbahelper/vbaapplicationbase.cxx?r=da9b11a5#410
[5] https://opengrok.libreoffice.org/xref/core/oovbaapi/ooo/vba/word/XApplication.idl?r=c9b57b72#55
[6] https://opengrok.libreoffice.org/xref/core/sw/source/ui/vba/vbaapplication.cxx?r=c9b57b72#416
Comment 1 Roman Kuznetsov 2022-08-12 19:26:01 UTC
Confirm the problem in

Version: 7.5.0.0.alpha0+ / LibreOffice Community
Build ID: d75c5c1f61a174b3b333e9db6536ab15cc37d00b
CPU threads: 4; OS: Mac OS X 12.5; UI render: Skia/Metal; VCL: osx
Locale: ru-RU (ru_RU.UTF-8); UI: en-US
Calc: threaded Jumbo
Comment 2 Baole Fang 2023-03-13 00:56:45 UTC
I start working on this.
Comment 3 Commit Notification 2023-03-13 15:17:29 UTC
Baole Fang committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a6edfaaeb02169d90d8b414c480257b1ec0bcaad

tdf#150281: Fix CentimetersToPoints in Calc

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.