Nov 28, 2013 Replies: 13 Here is a port to B4J of my BasicLib script interpreter. Attachments BasicLib1.0.zip BasicLib1.0.zip 101.3 KB · Views: 1,278 Click to expand...
W wl Well-Known Member Licensed User Longtime User Feb 8, 2014 #2 When I try to build the demo application I get an error on "MsgBoxes" (not found). I'm running B4J 1.5 Thanks
When I try to build the demo application I get an error on "MsgBoxes" (not found). I'm running B4J 1.5 Thanks
Erel B4X founder Staff member Licensed User Longtime User Feb 9, 2014 #3 Have you added this library: Msgbox library ?
W wl Well-Known Member Licensed User Longtime User Feb 9, 2014 #4 I knew I was missing a library but could not find it. Now it's working. Thanks !
W wl Well-Known Member Licensed User Longtime User Feb 10, 2014 #5 Hi, I'm trying the demo app and inserted some testing scripts but run into some strange errors Code: Copy Dim b(2) b(0) = "hello" b(1) = "world" Foo (b) Sub Foo(c) MsgBox(c(0)) MsgBox(c(1)) End sub -->local variable can not be an array when the second MsgBox is to be shown How can you pass arrays to subs ? Code: Copy For i = 0 to 1 MsgBox(i) Next -> No program line to be executed after NEXT Thanks ! Last edited: Feb 10, 2014
Hi, I'm trying the demo app and inserted some testing scripts but run into some strange errors Code: Copy Dim b(2) b(0) = "hello" b(1) = "world" Foo (b) Sub Foo(c) MsgBox(c(0)) MsgBox(c(1)) End sub -->local variable can not be an array when the second MsgBox is to be shown How can you pass arrays to subs ? Code: Copy For i = 0 to 1 MsgBox(i) Next -> No program line to be executed after NEXT Thanks !
W wl Well-Known Member Licensed User Longtime User Feb 10, 2014 #6 OK, I found something out: This works Code: Copy 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 ?): Code: Copy 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
OK, I found something out: This works Code: Copy 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 ?): Code: Copy 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
agraham Expert Licensed User Longtime User Feb 11, 2014 #7 wl said: How can you pass arrays to subs ? Click to expand... 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? Thanks ! Click to expand... 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.
wl said: How can you pass arrays to subs ? Click to expand... 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? Thanks ! Click to expand... 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.
W wl Well-Known Member Licensed User Longtime User Feb 11, 2014 #8 Thanks agraham, But I tend to disagree that "you don't need to pass arrays to subs"... Having all kinds of global variables just is something you would want to avoid. Nevertheless: great work !
Thanks agraham, But I tend to disagree that "you don't need to pass arrays to subs"... Having all kinds of global variables just is something you would want to avoid. Nevertheless: great work !
agraham Expert Licensed User Longtime User Feb 11, 2014 #9 wl said: But I tend to disagree that "you don't need to pass arrays to subs" Click to expand... 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.
wl said: But I tend to disagree that "you don't need to pass arrays to subs" Click to expand... 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.
W wl Well-Known Member Licensed User Longtime User Feb 16, 2014 #10 Hi, Still experimenting ... I noticed I run into some strange errormessages when I have a space between the name of a sub and the opening parenthesis: Code: Copy Foo("Hello world") rem NOTICE THE SPACE BELOW between Foo and ( Sub Foo (b) MsgBox (b) End sub --> NumberFormatException When I remove the space it's all OK. Is this intended ? Thanks
Hi, Still experimenting ... I noticed I run into some strange errormessages when I have a space between the name of a sub and the opening parenthesis: Code: Copy Foo("Hello world") rem NOTICE THE SPACE BELOW between Foo and ( Sub Foo (b) MsgBox (b) End sub --> NumberFormatException When I remove the space it's all OK. Is this intended ? Thanks
agraham Expert Licensed User Longtime User Feb 16, 2014 #11 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. Let's call it a feature!
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. Let's call it a feature!
W wl Well-Known Member Licensed User Longtime User Feb 16, 2014 #12 Would be nice to fix it and give me a free license for noticing the '"feature" The code example in the helpfile also contains a space Code: Copy Sub ShowMean Msgbox("The mean of 20 and 30 is " & crlf & Mean(20,30)) End Sub Sub Mean (a, b) Return (a+b)/2 End Sub
Would be nice to fix it and give me a free license for noticing the '"feature" The code example in the helpfile also contains a space Code: Copy Sub ShowMean Msgbox("The mean of 20 and 30 is " & crlf & Mean(20,30)) End Sub Sub Mean (a, b) Return (a+b)/2 End Sub
W wl Well-Known Member Licensed User Longtime User Feb 20, 2014 #13 Hi, One other question: is there a possibility in a host method (called by 'callsub') to access a global array (based on it's name or something) ? Thanks !!
Hi, One other question: is there a possibility in a host method (called by 'callsub') to access a global array (based on it's name or something) ? Thanks !!
W wl Well-Known Member Licensed User Longtime User Feb 20, 2014 #14 Ok, I found it: you can use: Basic.GetArrayLength(<varname>) Basic.GetArrayItem(<varname>, index) ...
Ok, I found it: you can use: Basic.GetArrayLength(<varname>) Basic.GetArrayItem(<varname>, index) ...