473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 13689
George wrote:
I want to create a unique id for each of a set of objects.


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

Daniel.

"Leon Mayne [MVP]" <l.*********@uea.ac.uk> wrote in message
news:uV****************@TK2MSFTNGP10.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.NewGuid().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.NewGuid().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.NewGuid)
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.*********@uea.ac.uk> wrote in message
news:uY**************@tk2msftngp13.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.NewGuid().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
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
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...
26
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...
10
by: Crirus | last post by:
Is there a function that return some random ID like string alphanumeric? Like this: A35sDsd1dSGsH Thanks Crirus
2
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...
5
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...
16
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.