Function that creates the ControlID

Simple question: is the function that creates each WebControl.ControlID exposed and available to use in a custom class ?

If you create a control variable it has a ControlID you can use.

Dim ws as new WebSeparator System.debuglog ws.Control ID

You’ve got me curious, what are you trying to do with it?

Me too

I followed the iOSTableView blog post here:

I would like each row to have a unique ID so I thought the best way would be to use:

//row is a custom class
//row.ID is a String property

row.ID = iOSTableView1.controlID + “_” + FunctionToCreateUniqueID()[/code]

At first I was using the following:

row.ID = iOSTableView1.controlID + "_" + Hex(Ticks) + Hex(Rnd() * Ticks)

But soon realized it created collisions

each row isn’t a web control in this though
thats kind of important here

you should be able to generate a nice unique one with something like

       dim d as new date()
       dim idSuffix as string = str(d.TotalSeconds,"#.0000000")
       idSuffix = idSuffix.replaceAll(".","")
       row.ID = iOSTableView1.controlID + "_" + idSuffix

ah I see the bug report you filed related to this thread

Hex isn’t helping you here :slight_smile:

Yes Norman, I understand that in the original iOSTableView each row isn’t a webcontrol.

Unfortunately your solution seems to be even worse than mine if two or more rows are created at the same second (in a loop for example), they would end up having the same ControlID.

I ended up generating the unique ID like this:

Dim u as UInt64 = Microseconds //convert microseconds to a UInt64 or Hex function will fail
row.ID = iOSTableView1.controlID + "_" + Hex(u)

And at the same time discovered a bug with Hex function: feedback://showreport?report_id=44287

Make a method for creating your control ids and stick them into a static array. Then when you create each one, check to make sure it doesn’t exist already.

And at the same time discovered a bug with Hex function: feedback://showreport?report_id=44287[/quote]

I doubt that one will get altered as it runs the risk of breaking a existing code quietly
Its been that way for a VERY long time

But its not hard to write your own

Function ToHex(d as double) As String
  dim mb as new memoryblock(8)
  mb.LittleEndian = false
  mb.DoubleValue(0) = d
  return MBtoHexString( mb) 
End Function

Function MBtoHexString(mb as memoryblock) As string
  dim s as string
  for i as integer = 0 to mb.Size-1
    dim hexDigit as string = hex(mb.byte(i))
    if hexdigit.Len() < 2 then hexdigit = "0" + hexdigit
    s = s + hexdigit
  return s
End Function

The new framework does a better job of this BUT IMHO an Int8 with 127 in it should return “7F” and an int 16 with 127 in it should return “007F” by default - but it doesn’t - it returns “7F” - it basically ignores zero bytes. You have to ask for a certain number of digits (and thats a function of the number of bits which you cant get except by hardcoding things)
Negatives seem to be handled correctly

  dim i32 as integer = 127
  dim t32 as text = i32.ToHex // I expect 32 bits or 4 bytes but I get "7F"
  dim i64 as int64 = 127
  dim t64 as text = i64.ToHex // I expect 64 bits or 8 bytes but I get "7F"
  // you MST specify how many digits you want 
  // which is a functipn of the number of bits which
  // there is NO runtime way to know except by hard coding it
  dim t32a as text = i32.ToHex(8)
  dim t64a as text = i64.ToHex(16)

you get a text and can convert that to a string and off you go

new framework win !

I generate my own IDs like this:

[code]Function GenerateUUID() As String
dim strRet as String

dim strInput as String = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
dim intInputLen as Integer = strInput.Len
for intCycle as integer = 1 To 10
Dim r as New Random
strRet = strRet + strInput.Mid( r.InRange( 1, intInputLen ), 1 )
return strRet
End Function

Hope that helps!

Thanks to all for your help.

By searching for base62 on the web, which is the “encoding” of Xojo WebControl IDs I ended up on this site:

They have a very handy function to convert any integer or list of integers to a reversible hash.
It is now available for Xojo:

Big fan of hashid, I do recommend it