Bug 135673 - VBA 'For Each' statement 'Data type mismatch.' error
Summary: VBA 'For Each' statement 'Data type mismatch.' error
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
(earliest affected) release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
Depends on:
Reported: 2020-08-12 16:05 UTC by Max A. Dednev
Modified: 2020-08-14 04:45 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:
Regression By:


Note You need to log in before you can comment on or make changes to this bug.
Description Max A. Dednev 2020-08-12 16:05:58 UTC
I have the VBA macros with 'For Each' statements, perfectly working in LO 6.4 and earlier versions. But when I upgraded LO to 7.0.3 I've found, that this macros gives an error: "Inadmissible value or data type. Data type mismatch.".

I've tried an example from LO help (https://help.libreoffice.org/7.0/en-US/text/sbasic/shared/03090202.html?DbPAR=BASIC#bm_id3149205):
Sub list_iteration
    cutlery = Array("fork", "knife", "spoon")
    For Each item in cutlery
        Print item
    Next ' item
End Sub

I't doesn't work and gives me exactly the same error.

I've also tried LO unit test (https://git.libreoffice.org/core/+/0444fbe7515501a7997516e05329e2b2fda00dd3/core/basic/qa/basic_coverage/test_For_loops.vb):

Function doUnitTest
  Dim s1 As Integer, s2 As Integer, value As Integer
  numbers = Array(3,4,5,6,7,8,9,10,11)
  For Each value in numbers
    s1 = s1 + value
  Next value
  ' FOR .. TO .. STEP ..
  For value = 5 To 21 Step 3
    s2 = s2 + value
  Next value
  If s1<>9*7 Or s2<>3*25 Then
    doUnitTest = 0
    doUnitTest = 1 'Ok
  End If
End Function

It also produces the same error.

I've checked this problem in Linux under Debian Buster:
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster
and using LO win64 build under Windows 10 x86-64 - errors are the same.
Comment 1 raal 2020-08-12 19:34:10 UTC
I cannot reproduce with Version:
Build ID: 6ad2f463784a24c566477cdd60ae729651bb8564
CPU threads: 4; OS: Linux 4.15; UI render: default; VCL: gtk3
Locale: cs-CZ (cs_CZ.UTF-8); UI: en-US
Calc: threaded

Please can you test in dev version? Thank you

Comment 2 Max A. Dednev 2020-08-13 06:05:42 UTC
I've checked latest dev version:
Build ID: <buildversion>
CPU threads: 4; OS: Linux 5.6; UI render: default; VCL: kf5
Locale: ru-RU (ru_RU.UTF-8); UI: ru-RU
TinderBox: Linux-rpm_deb-x86_64@86-TDF, Branch:master, Time: 2020-08-11_15:13:29
Calc: threaded

Both provided test scripts work without errors. My original ods file with 'for each' macros also works fine.

I've double checked my LO 7.0 installation:
Build ID: 8061b3e9204bef6b321a21033174034a5e2ea88e
Потоков ЦП: 4; ОС: Linux 5.6; Отрисовка ИП: по умолчанию; VCL: kf5
Locale: ru-RU (ru_RU.UTF-8); ИП: ru-RU
Calc: threaded

LO 7.0 in safe mode gives the same error.
Comment 3 QA Administrators 2020-08-14 04:33:29 UTC Comment hidden (obsolete)
Comment 4 raal 2020-08-14 04:45:39 UTC
Thanks for the test. Closing the bug.