Page 1 of 1

[Solved] BASIC runtime error; Argument is not optional

Posted: Sun Mar 06, 2022 4:59 pm
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?

Re: BASIC runtime error; Argument is not optional

Posted: Sun Mar 06, 2022 6:05 pm
by JeJe
Try:

Code: Select all

 chr(n+64)

Re: BASIC runtime error; Argument is not optional

Posted: Mon Mar 07, 2022 2:42 pm
by Mr.Dandy

Code: Select all

function test(optional n as integer) as string
And manage yourself if n is missing

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

Posted: Sun Dec 31, 2023 1:31 am
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.