Android Question Error description: '(' expected.

Sadk

Member
B4X:
Error description: '(' expected.
Error occurred on line: 266
ConvertFromBase10 = strRes
Word: =




B4X:
Private Sub ConvertToBase10 (strNumberToConvert As String , intFromBase As Int )
    Dim valid As String
    Dim lett As String
    Dim indx As Long
    Dim res As Long
    Dim i As Long
    Dim alpha As String
    '
    If strNumberToConvert.Length = 0 Then
        Exit
    End If
    '
    alpha = "123456789ABCDEF"
    res = 0
    valid = alpha.SubString (intFromBase - 1)
    strNumberToConvert = strNumberToConvert.ToUpperCase
    [COLOR=rgb(226, 80, 65)] ConvertToBase10 = ""[/COLOR]
    For i = 1 To strNumberToConvert.Length
        lett = strNumberToConvert.SubString2 (i, 0)
        indx = valid.IndexOf( lett)
        If indx = 0 And lett <> "0" Then
            Log ("invalid data")
            Exit
        End If
        res = intFromBase * res + indx
    Next
  [COLOR=rgb(226, 80, 65)]  ConvertToBase10 = res[/COLOR]

End Sub
Private Sub  ConvertFromBase10 (inRes As String, intToBase As Int)
    Dim res As Long
    Dim A As Long
    Dim C As Long
    Dim strRes As String
    Dim alpha As String
 
    alpha = "123456789ABCDEF"
    res = inRes
    strRes = ""
    A = (res / intToBase)
    C = res - A * intToBase
    Do While (A + C > 0)
        If C = 0 Then
            strRes = "0" & strRes
        Else
            strRes = alpha.SubString2 (C, 0) & strRes
        End If
        res = A
        A = (res / intToBase)
        C = res - A * intToBase
    Loop
   [COLOR=rgb(226, 80, 65)] ConvertFromBase10 = strRes[/COLOR]

End Sub
 
Solution
is Wrong
B4X:
ConvertFromBase10 = strRes
You're getting the b4x grammar wrong. You don't have to use the function name for returning the result. This is in the grammar of other languages

Change to
B4X:
Return strRes

Gabino A. de la Gala

Active Member
Licensed User
Longtime User
In B4X, the way to assign the value that the functions have to return is always done in the same way:
B4X:
Return ValueDesired
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
is Wrong
B4X:
ConvertFromBase10 = strRes
You're getting the b4x grammar wrong. You don't have to use the function name for returning the result. This is in the grammar of other languages

Change to
B4X:
Return strRes
 
Upvote 0
Solution

Sadk

Member
error in return "":
Error occurred on line: 262 (Main)
java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at b4a.ConvertBW.main._converttobase10(main.java:864)
    at b4a.ConvertBW.main._getdatafromfile(main.java:710)
    at b4a.ConvertBW.main._button1_click(main.java:658)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
 
Upvote 0

Star-Dust

Expert
Licensed User
This is a new mistake. Indicates that the string you want to convert to number is empty.

Open a new thread for this error indicating also the line that generates this error
 
Upvote 0
Top