Passing variables from one sub to another Libre Office basic

Hi,

I have found a few related answers but none of them seem to work for me, so I thought I would ask by myself.

I would like to simply pass two string arrays and an integer from one sub to another. To learn how to do that I tried to pass one integer like that:

Sub test
Dim Variable as Integer
Variable = 1
test1(Variable)
End Sub

Sub test1(Variable as Integer)
Print Variable
End Sub

However, when I ran this macro I got an error “Argument is not optional”. Does someone know how to fix that?

Hello,

This code works for me. Where is it stored; how are you executing it? If you run test1 then yes you get the error but not if you run test.

Oh okay I know what I was doing wrong now, I was running test1. Thanks a lot!

In LibreOffice Basic, when you click “Run” in IDE, it starts the function or sub where your cursor is. So if your cursor is inside Sub test1, then it is attempted to run (not Sub test), so it doesn’t have a parameter passed.

It works now, thanks a lot!