help with error

sarkis

Member
Licensed User
Longtime User
Hi all
Please help with error on the line with the last return
"Compiling code. Error
Error parsing program.
Error description: Missing Keyword: end sub
Occurred on line: 280
End If"

Sub Globals
Type indexn (ind1 As Int, ind2 As Int)
-----
End Sub

Sub Check_Move(tox As Int, sun As Int) As indexn
If psblL.ind1=tox AND psblL.ind2=sun Then Return psblL
Else
If psblR.ind1=tox AND psblR.ind2=sun Then Return psblR
Else
If psblB.ind1=tox AND psblB.ind2=sun Then Return psblB
Else
If psblT.ind1=tox AND psblT.ind2=sun Then Return psblT
Else
psblL.ind1=-1
psblL.ind2=-1
Return psblL
End If ------ error in this line
End If
End If
End If
End Sub


thanks for replying
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Try this code:
B4X:
Sub Check_Move(tox As Int, sun As Int) As indexn
    If psblL.ind1 = tox AND psblL.ind2 = sun Then 
        Return psblL
    Else If psblR.ind1 = tox AND psblR.ind2 = sun Then 
        Return psblR
    Else If psblB.ind1 = tox AND psblB.ind2 = sun Then 
        Return psblB
    Else If psblT.ind1 = tox AND psblT.ind2 = sun Then 
        Return psblT
    Else
        psblL.ind1 = -1
        psblL.ind2 = -1
        Return psblL
    End If
End Sub
Best regards.
 
Upvote 0

sarkis

Member
Licensed User
Longtime User
I cannot see the difference

Thanks for replay.
But I cannot see the difference between my and your code..
Would you please explain.
I can only add, that all return types are type of indexn.
May I return user define type?
Thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Have you tried the code I posted ?
You don't say if it works.

There are two main possibilities with the If / Then keywords :
One line statement
B4X:
If Test Then DoSomething1 Else DoSomething2
Or multiline statements
B4X:
If Test Then
  DoSomething1
Else If
  DoSomething2
Else
  DoSomething3
End If
In your code, with
B4X:
If psblL.ind1=tox AND psblL.ind2=sun Then Return psblL
means that you have a ONE line statement !
No Else nor End If !

Best regards.
 
Upvote 0

sarkis

Member
Licensed User
Longtime User
strange" if then else " structure

Thanks for explaining.
It works.
I only wanted to know why my code didn't.
It is strange but following code also have no error, although
I didn't check if it works .(I think it should )


Sub Check_Move(tox As Int, sun As Int) As indexn
If psblL.ind1 = tox AND psblL.ind2 = sun Then
Return psblL
Else
If psblR.ind1 = tox AND psblR.ind2 = sun Then
Return psblR
Else
If psblB.ind1 = tox AND psblB.ind2 = sun Then
Return psblB
Else
If psblT.ind1 = tox AND psblT.ind2 = sun Then
Return psblT
Else
psblL.ind1 = -1
psblL.ind2 = -1
Return psblL
End If
End If
End If
End If
End Sub

Thanks again
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
B4X:
If psblL.ind1 = tox AND psblL.ind2 = sun Then
    Return psblL
Else
    If psblR.ind1 = tox AND psblR.ind2 = sun Then
        Return psblR
    Else
        If psblB.ind1 = tox AND psblB.ind2 = sun Then
            Return psblB
        Else
            If psblT.ind1 = tox AND psblT.ind2 = sun Then
                Return psblT
            Else
                psblL.ind1 = -1
                psblL.ind2 = -1
                Return psblL
            End If
        End If
    End If
End If
The disadvantage of your code is that even if the first test is satisfied the progam executes also all the other tests.

With the code I posted this not the case, that's what Else If is for.

Best regards.
 
Upvote 0
Top