Guid2oid.mmbas

Function guid2oid(ByVal base64String As String) '28Nov08 http://creativecommons.org/licenses/by-sa/2.5/ http://www.activityowner.com 'convert topic.guid to oid 'Derived from: 1999 Antonin Foller, Motobit Software, http://www.motobit.com/tips/detpg_Base64/ Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" Dim ngroupall As String Dim dataLength, groupBegin dataLength = Len(base64String) For groupBegin = 1 To dataLength Step 4 Dim numDataBytes, CharCounter, thisChar, thisData, nGroup numDataBytes = 3 nGroup = 0 For CharCounter = 0 To 3 thisChar = Mid(base64String, groupBegin + CharCounter, 1) If thisChar = "=" Then numDataBytes = numDataBytes - 1 thisData = 0 Else thisData = InStr(1, Base64, thisChar) - 1 End If     nGroup = 64 * nGroup + thisData Next nGroup = Hex(nGroup) nGroup = String(6 - Len(nGroup), "0") & nGroup ngroupall = ngroupall & nGroup Next guid2oid = "{" & _ Mid(ngroupall,7,2)&Mid(ngroupall,5,2)&Mid(ngroupall,3,2)&Mid(ngroupall,1,2)& "-" & _ Mid(ngroupall,11,2)&Mid(ngroupall,9,2) &"-"& _ Mid(ngroupall,15,2)&Mid(ngroupall,13,2)&"-"& _ Mid(ngroupall,17,2)&Mid(ngroupall,19,2)&"-"& _ Mid(ngroupall,21,12)&"}" End Function