"Data Type Mismatch" Error while "For Each" Loop is working

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

"Data Type Mismatch" Error while "For Each" Loop is working

Post by sokolowitzky »

Hello,
I have found some macros in this forum. While testing them, I found out that I get error during "for each" loop.
I have found another code in wiki pages of openoffice, which contains "for each" loop, I received the same error.
I tried some other ways but no joy. Somehow I keep getting error.

Do you might have any idea about where I might be wrong?

Here is the code below, originally from(https://wiki.openoffice.org/wiki/Docume ... s#For_Each)

Code: Select all

SUB TEST_VARIABLE
Const d1 = 2
Const d2 = 3
Const d3 = 2
Dim i
Dim a(d1, d2, d3)
For Each i In a()
    ' ... Inner part of loop 
Next i
END SUB
Win10-OpenOffice 4.1/LibreOffice 7.4
JeJe
Volunteer
Posts: 2778
Joined: Wed Mar 09, 2016 2:40 pm

Re: "Data Type Mismatch" Error while "For Each" Loop is work

Post by JeJe »

Works for me - what are you putting in the loop?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
FJCC
Moderator
Posts: 9270
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: "Data Type Mismatch" Error while "For Each" Loop is work

Post by FJCC »

The code also works for me. Here is a modified version that prints the numbers 1 through 12. Does it work for you?

Code: Select all

SUB TEST_VARIABLE
Const d1 = 1
Const d2 = 2
Const d3 = 1
Dim i
Dim a(d1, d2, d3)

j=0
For Each i In a()
    j=j+1
    print j
Next i

END SUB
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
JeJe
Volunteer
Posts: 2778
Joined: Wed Mar 09, 2016 2:40 pm

Re: "Data Type Mismatch" Error while "For Each" Loop is work

Post by JeJe »

Code: Select all

SUB TEST_VARIABLE
Const d1 = 2
Const d2 = 3
Const d3 = 2
Dim i
dim a(d1, d2, d3)

a(0,0,0)="first"
a(2,3,2)="last"

For Each i In a()
msgbox i
    ' ... Inner part of loop
Next i
END SUB
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply