Android Question [Solved] for each: do not understand item-type-issue

Pflichtfeld

Active Member
Licensed User
Why do I get error in line 4 : "current delaration does not match previous one"
B4X:
Private Sub FlipHorizontal(img As B4XView, pkt() As Mypkt )
    'Spiegelt um Senkrechte, mitte img
    Dim ww as double=img.Width, pp As Mypkt
    For Each pp In pkt
        pp.x=ww-pp.x
    Next
End Sub
Each element in pkt is a pp, isn't it? If I omit the declaration of pp in line 3 like:
B4X:
Private Sub FlipHorizontal(img As B4XView, pkt() As Mypkt )
    'Spiegelt um Senkrechte, mitte img
    'rückgabe in Pkt
    Dim ww as double=img.Width
    For Each pp In pkt
        pp.x=ww-pp.x
    Next
End Sub
I get error in line 5: unknown type: object
Can anybody help me to understand?
 

OliverA

Expert
Licensed User
Longtime User
Do you have a global variable named pp?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
you need to set the type when you do a for each loop, like this:

B4X:
    Dim i(6) As Int = Array As Int(1,2,3,4,5,6)
    For Each nr As Int In i
        Log(nr)
    Next

if you have an array with different types you can do something like this:

B4X:
    For Each obj As Object In i
        If obj Is Int Then
            Dim nr As Int = obj
            Log(nr)
        End If
    Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…