Bug 148651 - VBA runtime error with VBA.FormatPercent
Summary: VBA runtime error with VBA.FormatPercent
Status: CLOSED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.2.6.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:7.4.0 target:7.3.4
Keywords:
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2022-04-18 14:12 UTC by David Yang
Modified: 2022-06-14 08:07 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
The game in question (1.26 MB, application/vnd.ms-excel.sheet.macroEnabled.12)
2022-04-18 14:13 UTC, David Yang
Details
How it looks line in VBA (32.78 KB, image/png)
2022-04-24 08:06 UTC, Mike Kaganski
Details
VBA is "project" (33.86 KB, image/png)
2022-04-24 08:31 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Yang 2022-04-18 14:12:37 UTC
Description:
I am somewhat abusing libreoffice by trying to open a VBA game for excel, which I was fairly aware would be a brutal test of the VBA support in libreoffice. There was actually another issue that prevents the file I'm using from getting to the issue that will be described here, but I passed through that one by blindly removing some offending lines and have not filed an issue for it yet because I'm still fairly unsure of the exact cause.

The VBA.FormatPercent() function appears to raise a runtime error, '12'. The original line that raises the error is:


Range("C45").Value = "LOCKED - Progress: " & VBA.FormatPercent(StatTotalBossesKilled / 10, 2)


But I've been able to confirm that just doing


VBA.FormatPercent(0 / 10, 2)


Also generates the error. For reference, the nonsense that I tried to open in libreoffice can be downloaded at https://carywalkin.itch.io/arenaxlsm

Steps to Reproduce:
1. Open the game downloadable at https://carywalkin.itch.io/arenaxlsm
2. Enable macros
3. There will be errors in Sub RestoreKeys(). Delete every line that raises an error, I deleted the lines for characters [,'.pyu].
4. Click "New game"

Actual Results:
We hit a VBA runtime error, '12', and land on an achievements screen

Expected Results:
I wouldn't actually know as I don't know what the file is supposed to look like when it works, but I assume it should begin some kind of game, and not raise the error.


Reproducible: Always


User Profile Reset: Yes



Additional Info:
I have fair confidence that this probably won't be the only VBA incompatibility blocking this file from running. A game built inside a spreadsheet probably isn't the primary target for support, but it'll probably raise a good amount of items that can be addressed to get closer to full VBA compatibility.
Comment 1 David Yang 2022-04-18 14:13:39 UTC
Created attachment 179640 [details]
The game in question
Comment 2 Roman Kuznetsov 2022-04-18 18:15:27 UTC
https://gerrit.libreoffice.org/c/core/+/133133
Comment 3 Julien Nabet 2022-04-19 07:49:44 UTC
Sorry, I submitted a patch for review (as indicated in https://bugs.documentfoundation.org/show_bug.cgi?id=148651#c2 by Roman) but forgot to assign myself the bugtracker.
Comment 4 David Yang 2022-04-19 09:23:11 UTC
Oh, thanks for getting on it fast. I'm expecting more nonsense out of this file, I'm on the fedora repo 7.2.6.2 right now but I can switch to nightlies for the time being to test and bring up reports of the next stumbling block in the file faster
Comment 5 Commit Notification 2022-04-21 08:00:13 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/98f88ac1ffaee21f38615f9db27691b01491457c

tdf#148651: implement VBA.FormatPercent

It will be available in 7.4.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.
Comment 6 Julien Nabet 2022-04-21 08:11:51 UTC
Patch waiting for review in 7.3 here:
https://gerrit.libreoffice.org/c/core/+/133246
Comment 7 Julien Nabet 2022-04-21 08:50:36 UTC
(In reply to Julien Nabet from comment #6)
> Patch waiting for review in 7.3 here:
> https://gerrit.libreoffice.org/c/core/+/133246

After some discussion, it's been decided to abandon this one since it's a new feature and we wouldn't like to introduce bugs in a branch.
Comment 8 Commit Notification 2022-04-21 17:52:47 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/07bf0ce4e7f04a79910cbe1340264863451f1926

tdf#148651: basic_macros: Add unittest

It will be available in 7.4.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.
Comment 9 Commit Notification 2022-04-22 16:47:02 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/975bc84af3b3b3d251e68bcb86b0d0e619e0987c

tdf#148651: implement VBA.FormatPercent

It will be available in 7.3.4.

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.
Comment 10 David Yang 2022-04-23 09:54:36 UTC
Error still being raised in latest nightly, same file. Error message has slightly changed now, an additional line that reads "Variable not defined" has been added to the error popup. Original reproduction steps still applicable, occurs with both the original and simplified lines. Version readout from the nightly this was produced on:

Version: 7.4.0.0.alpha0+ / LibreOffice Community
Build ID: 8279d89d6e037def78f50c72fab2116ca56bef52
CPU threads: 12; OS: Linux 5.16; UI render: default; VCL: gtk3
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: CL

Downloaded from nightlies, Linux-rpm_deb-x86_64@tb87-TDF (rpm) 	2022-04-23 09:02:38.
Comment 11 Julien Nabet 2022-04-23 10:36:06 UTC
David: please open a new bugtracker and indicate what line (and its content) triggers the pb.
A minimum macro to reproduce the pb would be more relevant instead of the whole game which must use a lot of VBA functions.
Comment 12 David Yang 2022-04-23 10:41:45 UTC
Both the original line and the simplified VBA.FormatPercent(0 / 10, 2) line from initial report still produce the error, will open new item in a moment
Comment 13 Julien Nabet 2022-04-23 11:14:55 UTC
(In reply to David Yang from comment #12)
> Both the original line and the simplified VBA.FormatPercent(0 / 10, 2) line
> from initial report still produce the error, will open new item in a moment
If I run:
Option VBASupport 1

Sub Main
msgbox(FormatPercent(0/10, 2))
End Sub

I got no error and LO displays a popup containing 0.00%
(English UI, French local so decimal separator = ',')
Comment 14 David Yang 2022-04-23 12:48:39 UTC
Alright, I see what the issue is, the calls in this file are prefaced with VBA, so it's VBA.FormatPercent(0 /10, 2) vs FormatPercent(0 /10, 2). If the libreoffice standard is to omit the VBA at the front then I'll do a little sweep and probably find a different function to report on.
Comment 15 Julien Nabet 2022-04-23 14:37:23 UTC
(In reply to David Yang from comment #14)
> Alright, I see what the issue is, the calls in this file are prefaced with
> VBA, so it's VBA.FormatPercent(0 /10, 2) vs FormatPercent(0 /10, 2). If the
> libreoffice standard is to omit the VBA at the front then I'll do a little
> sweep and probably find a different function to report on.

Unless ignoring "VBA." may be an option?
Mike: any thoughts here?
Comment 16 Mike Kaganski 2022-04-23 21:17:02 UTC
(In reply to Julien Nabet from comment #15)

We better use the VBA object for those VBA compatibility functions, and just make that object the "default" to allow skip it. Because not any function may be prefixed with VBA.

But definitely a different issue.
Comment 17 Julien Nabet 2022-04-24 08:02:14 UTC
(In reply to Mike Kaganski from comment #16)
> (In reply to Julien Nabet from comment #15)
> 
> We better use the VBA object for those VBA compatibility functions, and just
> make that object the "default" to allow skip it. Because not any function
> may be prefixed with VBA.
> ...
What do you mean "VBA object"? Where can I find this in LO code?
Comment 18 Mike Kaganski 2022-04-24 08:06:50 UTC
Created attachment 179751 [details]
How it looks line in VBA

(In reply to Julien Nabet from comment #17)

I mean we need to introduce it, to match what looks to be the case in VBA.

Maybe I'm wrong ... is there a documentation on that "VBA" prefix thing?
Comment 19 Mike Kaganski 2022-04-24 08:31:22 UTC
Created attachment 179752 [details]
VBA is "project"
Comment 20 Julien Nabet 2022-04-24 11:19:47 UTC
(In reply to Mike Kaganski from comment #19)
> Created attachment 179752 [details]
> VBA is "project"

Ok so VBA.FormatPercent should be ok since "VBA" is a valid project.
Comment 21 Maurice Massey 2022-06-14 07:13:24 UTC Comment hidden (spam)
Comment 22 David Yang 2022-06-14 07:15:19 UTC
It's a dark time when spambots discover bug report portals