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

Discussion in 'B4J Questions' started by Mashiane, Jan 5, 2019.

  1. Mashiane

    Mashiane Expert Licensed 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..

    Sub StrParse(delim As String, mvField As StringAs 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
    For itemsCnt = 0 To itemsTot
            output(itemsCnt) = items.Get(itemsCnt)
    Return output
    End Sub
    Whilst its good B4J code, returns an error in BANano, these i.e. String() are not supported?
  2. alwaysbusy

    alwaysbusy Expert Licensed 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:
    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) = 
    Works also (although would not if the code ever passed through this in B4J):
    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) = ""
    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.
    Mashiane and Erel like this.
  1. 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.
    Dismiss Notice