Android Question How add classes?

Spright

Active Member
I am adding datatype point (i know vector2d exist, this is actually an excericse in OO in B4a).

so i would normally think about it like this
B4X:
Class Point

    Dim mX As Float
    Dim mY As Float

    Sub New(x As Float,y As Float)
        mX = x
        mY = y
    End Sub

End Class

So i added a class module, adn filled it in, I noticed there was a place for vars, so i moved them there.Of course it's still wrong, but I'm lacking examples hw to do ir correctly?

B4X:
Sub Class_Globals
   
    Private mX As Float
    Private mY As Float
   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   
End Sub

Class Point

    Sub New(x As Float,y As Float)
        mX = x
        mY = y
    End Sub

End Class
 

aeric

Expert
Licensed User
Longtime User
I thought using Type also will do.

B4X:
Type Point(mX As Float, mY As Float)

1683697261544.png
 
Last edited:
Upvote 0

Spright

Active Member
How do you actually use these examples? I could not find how to create new objects
If you want the class above to output an object like so:

B4X:
Sub clone : Point()
    Return New Point(mx,my)
EndSub
 
Upvote 0
Top