Home All Groups Group Topic Archive Search About

GUIDS not creating correctly in vb.net

Author
11 Nov 2006 11:10 PM
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.

Author
11 Nov 2006 11:23 PM
Tom Leylan
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


<d***@dodeonline.com> wrote in message
Show quoteHide quote
news:1163286613.497291.126070@h48g2000cwc.googlegroups.com...
> 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.
>
Author
11 Nov 2006 11:31 PM
doug
Thanks Tom - that worked a treat :)

Cheers,

Doug.
Tom Leylan wrote:
Show quoteHide quote
> 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
>
>
> <d***@dodeonline.com> wrote in message
> news:1163286613.497291.126070@h48g2000cwc.googlegroups.com...
> > 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.
> >