empty GUID from string in VB2005

C

Charles Hunt

Hi,

When running this code in VB2003

Sub guidtest()

Dim gstring As String

Dim gid As Guid

gstring = Guid.NewGuid().ToString

gid = New Guid(gstring)

End Sub

variable GID gets the correct value derived from gstring - however when i do
this in VB2005 it doesn't work - i just get an empty GUID - this seems like
a fairly serious problem so i am assuming i have made some incorrect basic
assumptions.

my installation of VS2005 went pretty smoothly from memory and it pretty
much has default options.

Can anyone replicate this problem / error?

is it a bug in VS/VB or .NET?

I look forward to hearing from anyone with any ideas here as I have spent
about 10 hours trying to see what I have done wrong.

best

Charles
 
C

Cor Ligthert [MVP]

Charles,

Sorry however your code looks so strange in my eyes, probably you mean.

\\\
dim gid as Guid = Guid.NewGuid
dim gstring = gid.ToString
///
Try to avoid using strings as intermediate, you see people do that as well
with datetime.

I hope this helps,

Cor
 
K

Ken Tucker [MVP]

Hi,

I added this line after you created gid.

MessageBox.Show(gstring, gid.ToString)

I get the same value in the caption and text.



Ken
 
C

Charles Hunt

Hi,

Which version of VB did you use? If I use VB2003 it works, if I use VB2005
it doesn't work.

best

Charles
 
C

Charles Hunt

Hi,

No my code is intentionally trying to create a GUID from a string.. not the
other way around. If I try the way you suggest it works fine - but that is
not the problem I was trying to demonstrate.

Thanks anyway.

Charles
 
C

Charles Hunt

Hi,

hmmm.. actually that does work, but my original post demonstrates a problem
where the gid object when inspected with a break point shows as "empty" -
but the .tostring method does infact yield a correct value.

This is a bit different in VB2003 because gid appears in the debugger
correctly (or as expected) but not in VB2005 - where it shows up as
"empty" - is it my installation or have I just made an abvious goof.

best

Charles
 
A

Armin Zingler

Charles Hunt said:
Hi,

hmmm.. actually that does work, but my original post demonstrates a
problem where the gid object when inspected with a break point shows
as "empty" - but the .tostring method does infact yield a correct
value.

This is a bit different in VB2003 because gid appears in the
debugger correctly (or as expected) but not in VB2005 - where it
shows up as "empty" - is it my installation or have I just made an
abvious goof.

You didn't write how you have it displayed in the IDE: Tooltip? Watch
window? Locals window? The VB 2005 IDE shows all the instance and shared
members if you extend the tooltip. GUID.Empty is one member. If you look in
the locals window in VS 2003 and expand the object, it also shows the Empty
member, but not in the tooltip.


Armin
 
M

m.posseth

Just tried this in VB.Net 2003 and VB.Net 2005

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

guidtest()

End Sub

Sub guidtest()

Dim gstring As String

Dim gid As Guid

gstring = Guid.NewGuid().ToString

gid = New Guid(gstring)

MsgBox(gid.ToString)

End Sub


and it works as expected

hth

Michel Posseth [MCP]
 
C

Charles Hunt

Hi,

Yes, I think that is where I have become confused. The fact that the local
and watch windows don't show the guid value, but do expand to the empty
member made me think the guid was empty when in fact it isn't.

If I perform the gid.tostring when the code is at a breakpoint it all seems
ok. - Intutively i though the watch would display the value of the GUID
object - but it doesn't. (or if i try to ?gid in the command window)

thanks

Charles
 
C

Cor Ligthert [MVP]

Charles,

I tried it in both now, It is working for me exactly the same.

\\\
Dim gid As Guid = Guid.NewGuid
Dim gid2 As Guid = New Guid(gid.ToString)
///


Cor
 
C

Charles Hunt

Hi,

The problem I had was that in the watch window is doesn't show any value -
which made me think it was unassigned or empty. this is still puzzling me
but I will try accept it as "the way it is"

best

Charles


m.posseth said:
Just tried this in VB.Net 2003 and VB.Net 2005

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

guidtest()

End Sub

Sub guidtest()

Dim gstring As String

Dim gid As Guid

gstring = Guid.NewGuid().ToString

gid = New Guid(gstring)

MsgBox(gid.ToString)

End Sub


and it works as expected

hth

Michel Posseth [MCP]






Charles Hunt said:
Hi,

hmmm.. actually that does work, but my original post demonstrates a
problem where the gid object when inspected with a break point shows as
"empty" - but the .tostring method does infact yield a correct value.

This is a bit different in VB2003 because gid appears in the debugger
correctly (or as expected) but not in VB2005 - where it shows up as
"empty" - is it my installation or have I just made an abvious goof.

best

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top