Android Example Two functions on arrays

Pending confirmation by Erel, I post three functions about arrays and maps that may be useful.

The first is to verify that an object variable is an array:
B4X:
Public Sub IsArray(Var As Object) As Boolean
    Dim VarType As String = GetType(var)
    Return VarType.StartsWith("[")
End Sub



The second is to know the type of data contained in the array:
B4X:
Public Sub ArrayType(Var As Object) As String
    Dim Res As String

    Dim VarType As String = GetType(Var)

    If VarType.StartsWith("[") Then

        Dim SecondChar As String = VarType.SubString2(1,2)
        Select Case SecondChar
            Case "B"
                Res = "Byte"
            Case "S"
                Res = "Short"
            Case "I"
                Res = "Int"
            Case "J"
                Res = "Long"
            Case "F"
                Res = "Float"
            Case "D"
                Res = "Double"
            Case "C"
                Res = "Char"
            Case "L"
                Res = "String"
            Case Else
                Res = ""
        End Select

    End If

    Return Res
End Sub



The third is for testing whether a variable is a Map object:
B4X:
Public Sub IsMap(Var As Object) As Boolean
    Dim VarType As String = GetType(Var)
    Return VarType.Contains("Map$MyMap")
End Sub
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Thanks LucasMS, will add to my utils subs.
 

DonManfred

Expert
Licensed User
Longtime User
Thanks LucasMS, will add to my utils subs.

I´m building my own utils-subs-module... I´m sure yours is actually much bigger ;-)

May you want to share your list of utils-subs? ;-)
 

stevel05

Expert
Licensed User
Longtime User
I had thought about it, but trying to work out how to do it usefully without cluttering up the forum is the problem. Perhaps it may be appropriate to use the wiki. Any thoughts?
 

DonManfred

Expert
Licensed User
Longtime User
I had thought about it, but trying to work out how to do it usefully without cluttering up the forum is the problem.

Yes... I began a few days before and i´m using a testproject here where i put new code-snippets into the functions-module if i find something interesting here in the forum.

Perhaps it may be appropriate to use the wiki. Any thoughts?

It´s likely the same like grinding the forum, isnt it?

I think maybe we should consider to create such a "utils-sub-database" or code module? so to say a "community driven project"
 

stevel05

Expert
Licensed User
Longtime User
yes, I think a "community driven project" is the right way to go.

I thought of the wiki as it's potentially user editable.

We could possibly use the share your creations forum, but it would be better if subs could be categorized and searched independently. The database sounds like a good idea. It would benefit from code highlighting though.

I'm currently using BPak's BJNotes to store things I know I won't remember next time I want them.

Perhaps @Erel has some thoughts.
 

stevel05

Expert
Licensed User
Longtime User
I've just realized we've hijacked this thread, Sorry @LucaMs . I'll create a new thread in ChitChat. Perhaps Erel can delete the posts not relating to the thread. Sorry:oops:
 

LucaMs

Expert
Licensed User
Longtime User
You have not hijacked this thread (also because I do not know what that means, literally :D), but thank you, Steve.

Maybe I should change the title of the thread.

Maybe Chit-Chat would not be the most suitable place.

(forget it)

P.S. Please, remember that my english is not my english, is our english, mine and Google Translate; then, correct "us" :D
 
Last edited:
Top