Dim b(2)
b(0) = "Hello"
b(1) = "World"
Foo ("b")
sub Foo(a)
for i = 0 to GetTotalLen(a) - 1
MsgBox (GetItem (a, i))
next
end sub
But still this does not work (no possibility to have arrays as local variables ?):
B4X:
Foo2()
Sub Foo2()
Dim b(2)
b(0) = "Hello"
b(1) = "World"
Foo ("b")
End Sub
sub Foo(a)
for i = 0 to GetTotalLen(a) - 1
MsgBox (GetItem (a, i))
next
end sub
You can't, and don't need to. Arrays must be declared as Globals in the outer scope but can be re-Dimmed in Subs if necessary. Have you read the "Variables" section in the B4Script.chm help file?
The tokeniser needs to fill in a target line for the For statement to jump to on exit, a blank line is sufficient. I guess your Next was the last statement in the outer scope - hence the error message.
I didn't intend that as a blanket statement of philosophy but meant that in this particular case you can always use a "scratch" global array as a local array . This script language almost exactly mirrors, very intentionally, that of the now obsolete Basic4ppc as it was originally written as a scripting library for Basic4ppc applications.
It's not intended but in all the years since I originally wrote this I never noticed it as I never put a space before the parenthesis. .
It looks like the the space in the Sub definition is causing the first pass of the tokeniser to fail to recognise that Foo is a Sub so at runtime it thinks the call to Foo is an array access, hence the NumberFormatException.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.