Ask Your Question

Passing variables from one sub to another Libre Office basic

asked 2019-02-09 19:36:21 +0200

mav192 gravatar image


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
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?

edit retag flag offensive close merge delete



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.

Ratslinger gravatar imageRatslinger ( 2019-02-09 19:45:20 +0200 )edit

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

mav192 gravatar imagemav192 ( 2019-02-09 19:51:51 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-02-09 19:43:37 +0200

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.

edit flag offensive delete link more


It works now, thanks a lot!

mav192 gravatar imagemav192 ( 2019-02-09 19:52:04 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-09 19:36:21 +0200

Seen: 544 times

Last updated: Feb 09 '19