1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

Android Code Snippet [B4X] GUID

Discussion in 'Code Snippets' started by Erel, Nov 20, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Sub GUID As String
    Dim sb As StringBuilder
    For Each stp As Int In Array(844412)
    If sb.Length > 0 Then sb.Append("-")
    For n = 1 To stp
    Dim c As Int = Rnd(016)
    If c < 10 Then c = c + 48 Else c = c + 55
    Return sb.ToString
    End Sub

    Code to generate UUID version 4: https://www.b4x.com/android/forum/threads/guid-vs-uuid-can-i-use-guid-as-uuid.110970/#post-692302
    Last edited: Oct 31, 2019
  2. LucaMs

    LucaMs Expert Licensed User

    Very elegant and compact.
    Erel likes this.
  3. colboy

    colboy Member Licensed User

    I found this one some time ago, which seems to work well.

    Sub GetGuid As String
    Dim r As Reflector
        r.Target = r.RunStaticMethod(
    Return r.RunMethod("toString")
    End Sub
    Star-Dust likes this.
  4. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    on B4I:
    Bit.ToHexString is a unknown member.
  5. DonManfred

    DonManfred Expert Licensed User

    On B4A/B4J and B4I?
    The Code in #1 is Crossplatform.
  6. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    On B4A the code works, but in B4I i have a unknown member with this code:
  7. Erel

    Erel Administrator Staff Member Licensed User

    My mistake. It is fixed.

    In most cases BytesConverter.HexFromBytes should be used instead of Bit.ToHexString. Therefore it was not implemented in B4i. To keep this snippet simple I used Chr instead.
    DonManfred and Alexander Stolte like this.
  8. AscySoft

    AscySoft Active Member Licensed User

    Forgive me for asking this, but how should I implement code in post no1 to change my crashlytics build_id stored in "com_crashlytics_build_id.xml" that right now is created "manually" in manifest editor with CreateResource? I think I am missing something so simple!
  9. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Please make a new Thread for this question, thanks.:)
    Erel likes this.
  10. Star-Dust

    Star-Dust Expert Licensed User

    My version
    Sub GUID As String
    Dim stp As String = "00000000-0000-1000-a000-000000000000"
    Dim sb As String = ""

    For Index = 0 To stp.Length-1
    If stp.CharAt(Index)="0" Then
                sb=sb & 
                sb=sb & stp.CharAt(Index)
    End If
    Return sb.ToLowerCase
    End Sub
    Last edited: Oct 31, 2019
    advansis and Filippo like this.
  11. Filippo

    Filippo Expert Licensed User

  12. AscySoft

    AscySoft Active Member Licensed User

    I did not feel that this is not the topic of discussion. My question sounded rather like...how to use it, what is good for, what it's it pourpouse!
    Thank's @Filippo I was aware of your tool. It is a nice that someone was thinking about implementing a GUID change. I do think that only with external tools like yours one coud change "programatically" a GUID (for firebase). When I saw this code I was thinking that somehow @Erel implemented it by (native) code!

    Oh, I now realize it is a cross-platform code[b4x], I was thinking at it from a [b4a] perspective
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice