Android Question Next Expected

hibrid0

Active Member
Licensed User
Longtime User
I have this small function to add text to a list.
Work fine if I compile in a project.
But if I add the exact same function code to my main project, the compiler say:

Syntax Error
'next' expected
'(' expected

Anybody can explain, what I'm makin wrong?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim cadena As String
    cadena= "La batalla de Normandía, llamada en clave Operación Overlord, fue la operación militar efectuada por los Aliados durante la Segunda Guerra Mundial que culminó con la invasión de los territorios de Europa occidental ocupados por la Alemania nazi. La operación dio comienzo el 6 de junio de 1944 con el desembarco de Normandía (Operación Neptune, más conocida como el Día D). Un asalto aerotransportado llevado a cabo por mil doscientas aeronaves precedió al desembarco anfibio, que involucró a cinco mil barcos. El día 6 de junio, ciento sesenta mil soldados cruzaron el canal de la Mancha de Inglaterra a Francia y hacia finales de agosto las tropas aliadas en suelo francés eran más de tres millones."
'    cadena="Hola"
    Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
'    Activity.LoadLayout("main")
    justificar_izquierda(cadena, 10, 1)
'EditText1.Text=cadena


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub justificar_izquierda (cadenaj As String, maximo_caracteres As Int, maximo_lineas As Int)
    Dim SF As StringFunctions
    Dim listaS As List
    Dim Lista_final As List
    Dim lista3 As List
    Dim cadena_temporal As String
    Dim Cadena_final As String

    listaS.Initialize
    Lista_final.Initialize
    lista3.Initialize

    SF.Initialize
    listaS= SF.StringToList(cadenaj, False, False)


    For i=0 To listaS.Size -1
        cadena_temporal= listaS.Get(i) & cadena_temporal

        If cadena_temporal = maximo_caracteres Or cadena_temporal.Length > maximo_caracteres Then

            Lista_final.Add(Cadena_final)
            cadena_temporal=listaS.Get(i)
            Cadena_final=listaS.Get(i)
        Else If cadena_temporal.Length < maximo_caracteres Then
            Cadena_final=Cadena_final &" "& listaS.Get(i)
        End If
    
    Next

    If Cadena_final.Length < maximo_caracteres Then
        Lista_final.Add(Cadena_final)
    End If



        For i = 0 To Lista_final.Size -1
            Log(Lista_final.Get(i))
        Next

End Sub
 

Attachments

  • work.zip
    8.6 KB · Views: 163
Last edited:

hibrid0

Active Member
Licensed User
Longtime User
Yes I know, I have other project more bigger and only copy and paste my function and the compiles show the errors I say.

And show errors is in my new function. If I delete the new function the project compile without problem.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Without seeing exactly what you have done it's impossible to give to give a concrete answer.
The error says 'Next' expected.
It seems that you are missing a Next somewhere.
You should also look if you are missing somewhere a Then, End If or End Sub.
 
Upvote 0

hibrid0

Active Member
Licensed User
Longtime User
Hi Klaus thanks for your help.
I upload the project complete.
 

Attachments

  • problem.png
    problem.png
    103.7 KB · Views: 179
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Take a look at line 272. Should it be
B4X:
If cadena_temporal.LENGTH = maximo_caracteres
instead of
B4X:
If cadena_temporal = maximo_caracteres
? You can also shorten that line by using ">=" instead of the "...=.... Or .... >...." construction. There's also no need for the If clause on line 277. If something isn't greater than or equal to something else, it can only be less than that something else. I'm not sure if these are the cause of your problem but simplifying your logic will make it easier to diagnose the error and improve execution time.

I suspect your problem might be this, though: using "cadena_temporal=maximo_caracteres" in line 272, the parser interprets that as assigning an Int value to a String rather than evaluating a Boolean statement (that's why I think you should be adding .Length) and because of that, the construction of the If clause is disrupted.
 
Upvote 0

hibrid0

Active Member
Licensed User
Longtime User
I change it, but continue the same error.
If you see that code is exact same code work fine in the first post.
 

Attachments

  • problem.png
    problem.png
    121.2 KB · Views: 175
Upvote 0

sorex

Expert
Licensed User
Longtime User
you have nested IF/THEN's and one of then doesn't end.

since you added a line feed after the THEN it expects and END IF aswell
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Try removing the If clause on line 277. It's not necessary. Just have it be "Else" and then the next line. Also, you should heed those warnings above the Log window. It's not a good idea to not declare a variable type.

Also, the code is not the exact same. The error you are getting is different, now that you've made those changes. Before, it said "Word: Or". Now it says "Word: Then". That means you changed something that matters. This is a clue.
 
Upvote 0

hibrid0

Active Member
Licensed User
Longtime User
Solved, the problem was I declare the same name variable calle: "Maximo_caracteres" with other type on the global.


Thanks a lot!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Erel must have a look at this. Solved, no need anymore !
This line is supposed to be wrong
If cadena_temporal.Length >= maximo_caracteres Then
changing the line, for checking, to this works:
If i >= 6 Then
It seems that there is something strange with cadena_temporal.Length >= maximo_caracteres.
cadena_temporal.Length is an Int and maximo_caracteres also, so it should work.

Changing cadena_temporal to cadenatemporal and maximo_caracteres to maximocaracteres removes the error.
Setting cadenatemporal back to cadena_temporal is OK!
But setting maximocaracteres back to maximo_caracteres shows the error again.
I don't understand why !
But this line
If cadena_temporal.Length < maximo_caracteres Then
doesn't show the error !?

This is the routine I tested:
B4X:
Sub justificar_izquierda (cadenaj As String, maximo_caracteres As Int, maximo_lineas As Int)
    Dim SF As StringFunctions
    Dim listaS As List
    Dim Lista_final As List
    Dim lista3 As List
    Dim cadena_temporal As String
    Dim Cadena_final As String

    listaS.Initialize
    Lista_final.Initialize
    lista3.Initialize

    SF.Initialize
    listaS= SF.StringToList(cadenaj, False, False)

    Dim i As Int
    For i = 0 To listaS.Size -1
        cadena_temporal= listaS.Get(i) & cadena_temporal
        If cadena_temporal.Length >= maximo_caracteres Then
            Lista_final.Add(Cadena_final)
            cadena_temporal=listaS.Get(i)
            Cadena_final=listaS.Get(i)  
        Else
            Cadena_final=Cadena_final &" "& listaS.Get(i)          
        End If
    Next

    If cadena_temporal.Length < maximo_caracteres Then
        Lista_final.Add(Cadena_final)
    End If

    For i = 0 To Lista_final.Size -1
        Log(Lista_final.Get(i))
    Next
End Sub

EDIT:
I hadn't seen post#10 when I ansewered.
The problem is that hibrid0 declared a sub and a variable withe the same name !!!
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
that compiles fine, Klaus.

The only thing I commented were the 2 lines for that SF variable as I don't have that lib.
 
Upvote 0

hibrid0

Active Member
Licensed User
Longtime User
Erel must have a look at this.
This line is supposed to be wrong
If cadena_temporal.Length >= maximo_caracteres Then
changing the line, for checking, to this works:
If i >= 6 Then
It seems that there is something strange with cadena_temporal.Length >= maximo_caracteres.
cadena_temporal.Length is an Int and maximo_caracteres also, so it should work.

Changing cadena_temporal to cadenatemporal and maximo_caracteres to maximocaracteres removes the error.
Setting cadenatemporal back to cadena_temporal is OK!
But setting maximocaracteres back to maximo_caracteres shows the error again.
I don't understand why !
But this line
If cadena_temporal.Length < maximo_caracteres Then
doesn't show the error !?

This is the routine I tested:
B4X:
Sub justificar_izquierda (cadenaj As String, maximo_caracteres As Int, maximo_lineas As Int)
    Dim SF As StringFunctions
    Dim listaS As List
    Dim Lista_final As List
    Dim lista3 As List
    Dim cadena_temporal As String
    Dim Cadena_final As String

    listaS.Initialize
    Lista_final.Initialize
    lista3.Initialize

    SF.Initialize
    listaS= SF.StringToList(cadenaj, False, False)

    Dim i As Int
    For i = 0 To listaS.Size -1
        cadena_temporal= listaS.Get(i) & cadena_temporal
        If cadena_temporal.Length >= maximo_caracteres Then
            Lista_final.Add(Cadena_final)
            cadena_temporal=listaS.Get(i)
            Cadena_final=listaS.Get(i)   
        Else
            Cadena_final=Cadena_final &" "& listaS.Get(i)           
        End If
    Next

    If cadena_temporal.Length < maximo_caracteres Then
        Lista_final.Add(Cadena_final)
    End If

    For i = 0 To Lista_final.Size -1
        Log(Lista_final.Get(i))
    Next
End Sub

EDIT:
I hadn't seen post#10 when I ansewered.
The problem is that hhhh declared a sub and a variable withe the same name !!!

Guys thanks a lot, I solved the problem, the problem was the var called "maximo_caracteres" is an INT on the function, but I dont remember and I declare a var with the same name "maximo_caracteres" and the error by the analyser is not clear.

I look if I change the "maximo_caractres" by and INT number not show the error, then I see that the problem, I only change the name if the var on the function and compile again without problems.


Thanks a lot!
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I was under the impression that underscores were to be avoided when declaring variables, using a "-" instead (?)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
substraction math would look like fun when using a - in variable names :)

I just use capital so it will be

cadenaTemporal.Length >= maximoCaracteres
 
Upvote 0
Top