473,832 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I generate a GUID?

I want to create a unique id for each of a set of objects.

These ids may be generated on multiple machines simultaneously and must all
be different to each other.

There are an undefined number of machines involved (1 to dozens) and an
indeterminate number of objects (many to very many on each machine).

My best guess for a solution would be to use a GUID (all the machines have
an ethernet connection so a GUID generated on any of them should not
conflict with any other).

The question is how do I generate a GUID from VB.NET?

I don't really want to use unmanaged code if I can avoid it but I can write
some sort of managed wrapper for it if I have to.

Thanks, in advance,

George.
Nov 21 '05 #1
5 13717
George wrote:
I want to create a unique id for each of a set of objects.


Dim strGUID As String
strGUID = System.Guid.New Guid().ToString
Nov 21 '05 #2
That gives me an empty GUID (all zeros) not a newly generated unique
identifier.

Daniel.

"Leon Mayne [MVP]" <l.*********@ue a.ac.uk> wrote in message
news:uV******** ********@TK2MSF TNGP10.phx.gbl. ..
George wrote:
I want to create a unique id for each of a set of objects.


Dim strGUID As String
strGUID = System.Guid.New Guid().ToString

Nov 21 '05 #3
George wrote:
That gives me an empty GUID (all zeros) not a newly generated unique
identifier.


Are you sure you're using Guid.NewGuid() and not just Guid? Apparently just
Guid.ToString returns all zeros.

Copy and paste this code and run your app:

Dim strGUID As String
strGUID = System.Guid.New Guid().ToString
msgbox (strGUID)

And see if it still brings up a messagebox full of zeros. For me, this
returns a proper GUID.

Also see this:
http://www.dotnet247.com/247referenc...aspx?id=189797
Nov 21 '05 #4
Aha, yes you are right. NewGuid does generate a new guid. That is what I
expected it to do but ...

My problem it seems was in getting the value of this new guid.

I have the following:-

Private mGUID as Guid

Public Sub New()
Me.New(Guid.New Guid)
End Sub

Private Sub New(ByVal pGUID as Guid)
MyBase.New()
mGUID = pGUID
End Sub

I put a break point on the line after setting mGUID and investigated the
results using the command window:-

?mGUID
{System.Guid}
Empty: {System.Guid}
?mGUID.ToString
"188372b2-b106-40c6-89d8-6005f20369f5"

Thanks for your help,

George

"Leon Mayne [MVP]" <l.*********@ue a.ac.uk> wrote in message
news:uY******** ******@tk2msftn gp13.phx.gbl...
George wrote:
That gives me an empty GUID (all zeros) not a newly generated unique
identifier.
Are you sure you're using Guid.NewGuid() and not just Guid? Apparently

just Guid.ToString returns all zeros.

Copy and paste this code and run your app:

Dim strGUID As String
strGUID = System.Guid.New Guid().ToString
msgbox (strGUID)

And see if it still brings up a messagebox full of zeros. For me, this
returns a proper GUID.

Also see this:
http://www.dotnet247.com/247referenc...aspx?id=189797

Nov 21 '05 #5
George wrote:
Thanks for your help,

George


No Prob :-)
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
576
by: Jeff Lynch | last post by:
How do I create a new GUID programatically like the "Create Guid" tool does in VS.NET? -- Jeff Lynch "A BizTalk Enthusiast" http://dotnetjunkies.com/WebLog/jlynch/
6
3065
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub directory for each request so as to get rid of any file concurrency issue, e.g c:\working\unique-identifier1 for Request #1 c:\working\unique-identifier1 for Request #2
26
11579
by: John Grandy | last post by:
Is it possible to generate a 20 byte integer from a GUID that is "unique enough" ( just like a GUID is not truly unique , but is "unique enough" ). We identify transactions with GUIDs , but a partner web service has a 20 byte limit on transaction ID passed.
10
2624
by: Crirus | last post by:
Is there a function that return some random ID like string alphanumeric? Like this: A35sDsd1dSGsH Thanks Crirus
2
4556
by: Chris Dunaway | last post by:
I have a web service which is accessed by a windows forms application. When the application submits a unit of work (a "job"), I want to return a job receipt or tracking number back to the application. My requirements are these: 1. The receipt number must be unique (like a guid is unique) 2. The receipt must be NON sequential. 3. If possible, I'd like it to be 10 to 12 characters long. 4. If possible, I'd like to include only...
5
6678
by: Jason L James | last post by:
Hi all, is there a method or property of a class that will return a GUID in VB.NET that I can use as the PK of my DB. I do not want SQL to generate it as I can not then use SELECT @@IDENTITY to retrieve it. I want to try and mimic the functionality of
16
6941
by: Mark S. | last post by:
I'm a fan of the GUID, but the current project is looking to use a genuinely unique integer. Does the following do that? Math.Abs(System.Guid.NewGuid().GetHashCode()) TIA
6
4358
by: =?Utf-8?B?QWxwaGFwYWdl?= | last post by:
Hello, I want to generate a unique ID for each page of my Asp.Net application. My first step is to generate a new Guid when the page is loaded for the first time and registers, stores this new Guid in a Dictionary which is saved in the ApplicationState, then I add a hidden field to the page __PageID, so I can get this unique ID on other Postbacks. No problem. The problem is about hackers. They can modify my hidden field to another...
0
9795
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10781
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10541
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.