Generating a GUID with VB.NET

Introduction

This code generates Globally Unique Identifier (GUID),which can be used to uniqually identify elements in a database.

GUIDs identify objects such as interfaces and class objects. A GUID consists of one group of 8 hexadecimal digits,followed by three groups of 4 hexadecimal digits each,which are followed by one group of 12 hexadecimal digits.

Possessing a unique identifier makes it easy to store and retrieve information. This is especially useful when working with a database because a GUID makes an excellent primary key.

SQL Server integrates well with GUID usage. The SQL Server data type uniqueidentifier stores a GUID value. You can either generate this value within SQL Server—using the NEWID() function—or you can generate the GUID outside of SQL Server and insert it manually.

The base System class in the .NET Framework includes the GUID value type. In addition,this value type includes methods to work with GUID values. In particular,the NewGUID method allows you to easily generate a new GUID.

Language and Platform

VB.NET 2005

Compiler

This code segment is for VB.NET 2005

Version

1.0.0.0

Code

    Private Sub GenerateGUID()
        Dim strGUID As String        
        strGUID = System.Guid.NewGuid.ToString()        
        MessageBox.Show(strGUID )
    End Sub

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...