[Solved] BASIC runtime error; Argument is not optional

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
djbierman
Posts: 5
Joined: Sat Mar 05, 2022 12:50 pm

[Solved] BASIC runtime error; Argument is not optional

Post by djbierman »

I have the following function to translate a number (1... 26) into a character "A"..."Z"

Code: Select all

function test(n as integer) as string
dim s(26) as string
s(0)=" "
s(1)="A"
s(2)="B"
' etc. 
s(25)="C"
s(26)="Z"
test = s(n)
end function
it generates the runtime error with the arrow on the line with: test=s(n)
I am missing something (beginner).
BTW is any calc-function usable in Basic?
Last edited by MrProgrammer on Sun Mar 13, 2022 8:42 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
LibreOffice 7.0.5.2 OSX
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: BASIC runtime error; Argument is not optional

Post by JeJe »

Try:

Code: Select all

 chr(n+64)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: BASIC runtime error; Argument is not optional

Post by Mr.Dandy »

Code: Select all

function test(optional n as integer) as string
And manage yourself if n is missing
OpenOffice 4.1.12 - Windows 10
Rotnbair
Posts: 12
Joined: Wed Aug 23, 2023 10:01 pm

Re: [Solved] BASIC runtime error; Argument is not optional

Post by Rotnbair »

That worked for me too, thanks.

Both sub A and sub B called sub C (with 2 parameters). When called from sub A, sub C worked fine. When called from sub B, sub C always produced the run-time error "argument not optional". So I made both parameters optional; now A and B can call C with no errors.
Apache OpenOffice 4.1.14
Windows 11
Post Reply