B4J Question Check Object declare as type

invocker

Active Member
I have declare an object like a type

B4X:
Type filemanager(name As String ,size As String,LastModified As String ,folder As Boolean)

when I loop Throwt it with foreach
B4X:
For Each  FM As filemanager In myinfo.Values
                
        ....       
                    
    
            Next

in the last item see that fm =1 how can check if fm is atype I use this method but think that is not good for check mybe

B4X:
If  GetType(FM) = "b4j.example.b4xmainpage$_filemanager" Then

log("yes")
else

log("no")
end if
 
Solution
how can check if fm is atype

B4X:
Sub Process_Globals
    Type filemanager(name As String ,size As String,LastModified As String ,folder As Boolean)
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
 
    'create sample myInfo with 4 items; the 3rd item is a filemanager

    Dim myInfo As Map
    myInfo.Initialize
 
    myInfo.Put(101, 345)
    myInfo.Put(202, "hello")
 
    Dim fm As filemanager
    fm.name = "fm/name"
    fm.size = "fm/size"
    fm.LastModified = "fm/LastModified"
    fm.folder = False
    myInfo.Put(303, fm)
 
    myInfo.Put(404, 1.234)

    For Each o As Object In myInfo.Values
        If o Is filemanager Then
            Log("Yes" & TAB & (o Is filemanager))    'the "o is filemanager"...

emexes

Expert
Licensed User
how can check if fm is atype

B4X:
Sub Process_Globals
    Type filemanager(name As String ,size As String,LastModified As String ,folder As Boolean)
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
 
    'create sample myInfo with 4 items; the 3rd item is a filemanager

    Dim myInfo As Map
    myInfo.Initialize
 
    myInfo.Put(101, 345)
    myInfo.Put(202, "hello")
 
    Dim fm As filemanager
    fm.name = "fm/name"
    fm.size = "fm/size"
    fm.LastModified = "fm/LastModified"
    fm.folder = False
    myInfo.Put(303, fm)
 
    myInfo.Put(404, 1.234)

    For Each o As Object In myInfo.Values
        If o Is filemanager Then
            Log("Yes" & TAB & (o Is filemanager))    'the "o is filemanager" returns Boolean True or False
        Else
            Log("No" & TAB & (o Is filemanager))    'ditto
        End If
    Next

End Sub

Log output:
Waiting for debugger to connect...
Program started.
Hello world!!!
No    false
No    false
Yes    true
No    false
Program terminated (StartMessageLoop was not called).
 
Last edited:
Upvote 1
Solution

emexes

Expert
Licensed User
how can check if fm is atype

or even this ? use a Map to convert from Boolean True/False to "Yes"/"No" :

B4X:
Sub AppStart (Args() As String)
    Log("Hello world!!!")
 
    Dim YesNo As Map
    YesNo.Initialize
    YesNo.Put(True, "Yes")
    YesNo.Put(False, "No")
 
    'create sample myInfo with 4 items; the 3rd item is a filemanager
 
    Dim myInfo As Map
    myInfo.Initialize
 
    myInfo.Put(101, 345)
    myInfo.Put(202, "hello")
 
    Dim fm As filemanager
    fm.name = "fm/name"
    fm.size = "fm/size"
    fm.LastModified = "fm/LastModified"
    fm.folder = False
    myInfo.Put(303, fm)
 
    myInfo.Put(404, 1.234)

    For Each o As Object In  myInfo.Values
        Log(YesNo.Get(o Is filemanager))
    Next

End Sub

Log output:
Waiting for debugger to connect...
Program started.
Hello world!!!
No
No
Yes
No
Program terminated (StartMessageLoop was not called).
 
Upvote 0

emexes

Expert
Licensed User
or even this:

B4X:
Dim YesNo As Map
YesNo.Initialize
YesNo.Put(True,  "✅ Yes ?")
YesNo.Put(False, "❌ No  ?")

Log output:
Waiting for debugger to connect...
Program started.
Hello world!!!
❌ No  ?
❌ No  ?
✅ Yes ?
❌ No  ?
Program terminated (StartMessageLoop was not called).
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
by the magic of copy-and-paste eg:
B4X:
Log("? How do you find the index of the icons in the font or list all of them then copy out?")
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
or do you mean how to find icons from the list of thousands of Unicode characters?

1670683498281.png

although it helps to know that what we call ticks, Unicode calls checks, and when we say cheers!, Unicode says clink
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
I'd imagine that Log(Asc("?")) would give you the Unicode character number of ? but because B4X source code files are stored as UTF-8, I've taken to just inserting regular Unicode characters/emojis/icons as regular text, rather than as Chr(Unicode character number).

edit: interestingly, the font used for inline code here seems to have a different key glyph/icon/image to the font used for the regular text of this post.
 
Last edited:
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
This is what happens when I copy your code in B4J:

屏幕截图 2022-12-10 225222.png


I thought you have a tool to list all icons/symbols in font then copy its unicode out.
 
Upvote 0

emexes

Expert
Licensed User
This is what happens when I copy your code in B4J:

I'm not quite sure what the problem is, but I suspect it's probably thanks to different font files often representing characters - especially emojis and icons - in different styles.


I thought you have a tool to list all icons/symbols in font then copy its unicode out.

Nope, I just use the emoji picker of whichever program is closest to hand. Worst case is Google search eg unicode clinking, or use a site like:

https://emojipedia.org/clinking-glasses/

which has a copy-to-clipboard button.
 
Last edited:
Upvote 0
Top