GUID conversion

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
Folks,


I have generated a GUID. I want to convert it form it's hex output to just a number. Can anyone help please?

Here is the code so far:

VB.NET:
[size=2][/size][size=2][color=#008000]' Generate a GUID for the logging file [/color][/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] NewGuid [/size][size=2][color=#0000ff]As[/color][/size][size=2] Guid = Guid.NewGuid[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] myGuid [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String[/color][/size][size=2] = NewGuid.ToString("N") [/size][size=2][color=#008000]'N means no dashes
[/color][/size]

The output is something like:

22877b8675044489b9b309c7e0390a5f

but I need this as just a number...
Can anyone help pleasE?

Thank you
G.
 

dynamic sysop

Member
Joined
Jun 27, 2004
Messages
10
Location
Ashby-De-La-Zouch, UK.
Programming Experience
5-10
here's a quick thing i knocked together , not sure if it's exactly how you want it, but give it a go ...

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] gu [/size][size=2][color=#0000ff]As[/color][/size][size=2] Guid = [/size][size=2][color=#0000ff]Me[/color][/size][size=2].GetType.GUID[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] bt() [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2] = gu.ToByteArray[/size]
 
[size=2][color=#0000ff]For[/color][/size][size=2] x [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2] = 0 [/size][size=2][color=#0000ff]To[/color][/size][size=2] bt.Length - 2[/size]
[size=2][color=#0000ff]	Dim[/color][/size][size=2] temp1 [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2] = bt(x)[/size]
[size=2][color=#0000ff]	Dim[/color][/size][size=2] temp2 [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2] = bt(x + 1)
[/size][size=2][color=#0000ff]	Dim[/color][/size][size=2] str [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = temp1 & temp2
 
	Console.Write([/size][size=2][color=#0000ff]Integer[/color][/size][size=2].Parse(str, Globalization.NumberStyles.HexNumber))
 
[/size][size=2][color=#0000ff]Next[/color][/size]
 

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
I'm trying to generate 1 16-digit number from the GUID... the above code does not seem to be doing that. It didn't compile - so I modified it accordingly

Dim NewGuid As Guid = Guid.NewGuid
Dim myGuid() As Byte = NewGuid.ToByteArray
Dim hexString As String = ""
Dim i As Integer
Dim num As String
Dim Str As String
For i = 0 To (myGuid.Length - 2)

Dim temp1 As String = myGuid(i).ToString

Dim temp2 As String = myGuid(i + 1).ToString

Str = temp1 & temp2

Next i

num = Integer.Parse(Str, Globalization.NumberStyles.HexNumber)

 
Top Bottom