Generating unique ID using GUID

Tuesday, August 05, 2008
By keiji
Category: .NET, Tips, VBscript
Sometimes I wanted to generate a unique ID. I often uses random number combined with date/time. But, recently I found better way of getting that.
The trick is to use "GUID". It is kind of guaranteed to generate a unique ID.

If you are using VBscript, then the function is like this:
public function GenGUID()
        dim TypeLib,strTG
        Set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
        strTG = TypeLib.Guid
        GenGUID = mid(strTG, 2,len(strTG)-4)
        Set TypeLib = Nothing
end function

If you are using .NET language, then use the built-in function:
System.Guid.NewGuid.ToString()

Comments

N/A

Reply to

Subject:
Name:
E-Mail:
Comment:
(Max 1000 chars)
Confirmation Key:
Please enter the value displayed in the image.
Send Send