Ask Your Question
0

Passing variables from one sub to another Libre Office basic

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

mav192 gravatar image

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?

edit retag flag offensive close merge delete

Comments

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.

Ratslinger gravatar imageRatslinger ( 2019-02-09 19:45:20 +0100 )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 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

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

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

Comments

It works now, thanks a lot!

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

Question Tools

1 follower

Stats

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

Seen: 23 times

Last updated: Feb 09