Android Question Using Custom Type in a Sub declaration

JohnC

Expert
Licensed User
Longtime User
I'm trying to create a Custom Type and use it in a sub declare as one of the parameters.

Here is what I have, but the one line (indicated with an arrow) show "types do not match - error #22":

B4X:
Sub Process_Globals
    Type EventType(eventEvent As Int, eventError As Int)
    Public EventTypes As EventType
    EventTypes.eventEvent = 0: EventTypes.eventError = 1
End Sub


Sub SaveEvent(EType As EventType, EventText As String)

-->    If EType = EventTypes.eventError Then    'Types do not match (Warning #22)
            EventLine = " * "
        Else
            EventLine = "   "
        End If
    End if

End Sub

Any ideas what I am doing wrong?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Any ideas what I am doing wrong?
You are trying to compare a customTYPE with a single VALUE

B4X:
Sub SaveEvent(EType As EventType, EventText As String)
  If EType.eventError = 1 Then  
  End If
End Sub
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
But, I wanted to get away from having to remember the values of the custom type.

So I should use INT as the param type in the declaration like this:

B4X:
Sub SaveEvent(Etype as int, EventText as string)
     If Etype = EventTypes.eventError then
     end if
End Sub

Then I could call the sub like this:

B4X:
SaveEvent(EventTypes.eventError, "")

I just posted a wish item for this to be handled like intellisense:

https://www.b4x.com/android/forum/t...-sub-parameters-including-custom-types.72031/
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Sorry for the major editing of my post - I realized it was really two issues I needed to describe separately.
 
Upvote 0
Top