B4J Question [BANano]: [SOLVED] Support for String()

Mashiane

Expert
Licensed User
Longtime User
Hi there

In most of my existing subs I have used String(), whether this is being passed to a function or returned to a function. Whilst I know I can just use a list for such, I was dreading the re-writing, I will do it anyway.

Here is some example of this..

B4X:
Sub StrParse(delim As String, mvField As String) As String()
    Dim items As List = StrParse2List(delim,mvField)
    Dim itemsTot As Int = items.Size - 1
    Dim itemsCnt As Int
    Dim output(itemsTot) As String
    For Each strValue As String In output
        Log(strValue)
    Next
    For itemsCnt = 0 To itemsTot
        output(itemsCnt) = items.Get(itemsCnt)
    Next
    Return output
End Sub

Whilst its good B4J code, returns an error in BANano, these i.e. String() are not supported?
 

alwaysbusy

Expert
Licensed User
Longtime User
It is supported. The error in the B4J logs points to output: Dim output(itemsTot) As String which was not supported. 1.27+ will ignore the itemsTot to keep as close to native B4J as possible in the declaration while transpiling because JavaScript doesn't need this. If you want to prefill it with something you will have to use a for loop after the declaration.

Something like:
B4X:
Dim output(itemsTot) as String ' <--- transpiler will ignore the itemsTot so transpiling it to _output=[]
' if you want to prefill it use something like this:
for i = 0 to initemsTot - 1
    output(i) = ""
next

Works also (although would not if the code ever passed through this in B4J):
B4X:
Dim output() as String ' <--- transpiler also  _output=[]
' if you want to prefill it use something like this:
for i = 0 to initemsTot - 1 ' B4J would give an error 
    output(i) = ""
next

but as said, prefilling (dimming it to a certain size) is not needed for javascript. And the the B4J list is a lot more powerful anyway.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…