GUIDS not creating correctly in vb.net

  • Thread starter Thread starter doug
  • Start date Start date
D

doug

G'day all,

I'm a newbie to .net (7 years or so as a vb/asp programmer) and I'm
trying to create a GUID using the GUID type in vb.net

Here's the code I'm using to create it :

Public Function CreateGUID() As String
Dim objGUID As Object
objGUID = New Guid
CreateGUID = objGUID.ToString
End Function

This function returns to me a formatted string that kinda looks like a
GUID, but it is all zeros - can anyone help?

Cheers,

Doug.
 
Note that you declared the variable as type Object (but that's not it.)
You've created a blank GUID so you're seeing zeros.

Instead of a separate function try putting this in place of the call to your
function.

Dim s As String
s = Guid.NewGuid.ToString

Don't even need to instantiate a Guid object to get it.

Tom
 
Back
Top