VB.NET - To create a uuid using vb.net - Asked By abinav shankar on 25-Aug-11 02:30 AM

hi

How to create a uuid using vb.net
Cos mos replied to abinav shankar on 25-Aug-11 02:32 AM
Hi,

Private Sub GenerateGUID()

      Dim sGUID As String
      sGUID = System.Guid.NewGuid.ToString()
      MessageBox.Show(sGUID)

    End Sub
Reena Jain replied to abinav shankar on 25-Aug-11 02:36 AM
Hi,

try like this

' This code example demonstrates the Guid.NewGuid() method.
Imports System
 
Class Sample
  Public Shared Sub Main()
    Dim g As Guid
' Create and display the value of two GUIDs.
    g = Guid.NewGuid()
    Console.WriteLine(g)
    Console.WriteLine(Guid.NewGuid())
  End Sub 'Main
End Class 'Sample
'
'This code example produces the following results:
'
'0f8fad5b-d9cb-469f-a165-70867728950e
'7c9e6679-7425-40de-944b-e07fc1f90ae7
'
TSN ... replied to abinav shankar on 25-Aug-11 02:43 AM
hi..

In the following script, Imanually generate the GUID that I can use later in the application by usingVB.NET:
Private Sub GenerateGUID()
 
        Dim sGUID As String
        sGUID = System.Guid.NewGuid.ToString()
        MessageBox.Show(sGUID)
 
    End Sub
In the example, I define a string variable, sGUID, to hold aGUID that I will generate. Then I set the value of sGUID to the value returned bythe System.Guid.NewGuidmethod (using the System.Guidnamespace) and convert the result to a string using ToString(). The result is displayed in a messagebox.
dipa ahuja replied to abinav shankar on 25-Aug-11 02:50 AM
GUID (pronounced goo'id - Globally unique identifier) is a 128-bit integer that can be used to uniquely identify something. You may store users or products in your database and you want somehow uniquely identify each row in the database.

A common approach is to create a autoincrementing integer, another way would be to create a GUID for your products.
.
Response.Write(@"<br>System.Guid.NewGuid().ToString() = " + System.Guid.NewGuid().ToString());
 
Response.Write(@"<br>System.Guid.NewGuid().ToString(""N"") = " + System.Guid.NewGuid().ToString("N"));
 
Response.Write(@"<br>System.Guid.NewGuid().ToString(""D"") = " + System.Guid.NewGuid().ToString("D"));
 
Response.Write(@"<br>System.Guid.NewGuid().ToString(""B"") = " + System.Guid.NewGuid().ToString("B"));
 
Response.Write(@"<br>System.Guid.NewGuid().ToString(""P"") = " + System.Guid.NewGuid().ToString("P"));

Anoop S replied to abinav shankar on 25-Aug-11 03:08 AM
GUIDs identify objects such asinterfaces and class objects. A GUID consists of one group of 8 hexadecimaldigits, followed by three groups of 4 hexadecimal digits each, which arefollowed by one group of 12 hexadecimal digits.
 
In the following script, Imanually generate the GUID that I can use later in the application by usingVB.NET:
Private Sub GenerateGUID()
 
        Dim sGUID As String
        sGUID = System.Guid.NewGuid.ToString()
        MessageBox.Show(sGUID)
 
    End Sub
In the example, I define a string variable, sGUID, to hold aGUID that I will generate. Then I set the value of sGUID to the value returned bythe System.Guid.NewGuidmethod (using the System.Guidnamespace) and convert the result to a string using ToString(). The result is displayed in a messagebox.
Irfan Khan replied to abinav shankar on 25-Aug-11 03:24 AM

A globally unique identifier (GUID) is a unique number, generated by the computer system, that coders can use to refrence unique objects. 

Wiki defines a GUID as:
The value of a GUID is represented as a 32-character hexadecimal string, such as {21EC2020-3AEA-1069-A2DD-08002B30309D}, and is usually stored as a 128-bit integer. The total number of unique keys is 2128 or 3.4×1038 — roughly 2 trillion per cubic millimeter of the entire volume of the Earth. This number is so large that the probability of the same number being generated randomly twice is extremely small.

It is very easy to generate a GUID.

The System.GUID class contains the function “NewGuid

Example:

Dim strGuid As String = System.Guid.NewGuid.ToString

This would generate a GUID that would look something like this:

94864413-54d4-41b9-be87-a1ee63dd4800

We can tell by this GUID’s 3rd set of characters “41b9″ that this is a V4 GUID. “1xxx” would indicate a V1 GUID, which contains part of the MAC address of the computer it was generated on.