B4J Question Confusion about string and conversion

Discussion in 'B4J Questions' started by HARRY, Apr 7, 2015.

  1. HARRY

    HARRY Active Member Licensed User


    I am pretty new to Basic4Java and I have some basic questions:

    1) It is possible to add strings using Str1 + Str2. I know that is cleaner to add integers, but is should work?

    2) String1 & String2 is concatination . Right?

    3) Dim a as String
    Dim b as integer
    a=b & cr
    a stays empty, where as the value of b is 27 Why?

  2. stevel05

    stevel05 Expert Licensed User

    This works as expected, using extra characters, you can see that the CRLF has been added.

    Dim a As String
    Dim b As Int = 27
        a=b & 
    Log("*** " & a & " ***")
    Yes adding numeric values in strings will work provided they contain only numeric values, otherwise you will get a NumberFormat error.
  3. rwblinn

    rwblinn Well-Known Member Licensed User


    see example Subs

    Sub AddStringsAsNumber(Str1 As String, Str2 As StringAs Double
    Dim result As Double
    If IsNumber(Str1) AND IsNumber(Str2) Then
            result = Str1 + Str2
    End If
    Return result
    End Sub

    Sub ConcatenateStrings(Str1 As String, Str2 As StringAs String
    Return Str1 & Str2
    End Sub

    Sub AddCRLF(b As Int) As String
    Return b & CRLF
    End Sub

    Sub Test
    Log("AddStringsAsNumber: " & AddStringsAsNumber("19""58"))   'Result = 77
        Log("ConcatenateStrings: " & ConcatenateStrings("19""58"))         'Result = 1958
        Log("AddCRLF: Line1" & AddCRLF(27) & "Line2")                             'Result Line127Line2 (on next line)
    End Sub
    ellpopeb4a likes 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