Click here to Skip to main content
16,009,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

Please go through this function and tell me, is this the right way to generate a guid?
VB
Private Function billnumber() As Integer
        Dim num As String = System.Guid.NewGuid().ToString
        Dim charCount As Integer = 0
        For Each c As Char In num
            If Char.IsDigit(c) Then
                billnum += c.ToString()
                charCount += 1

            End If
            If charCount = 6 Then
                Exit For
            End If
        Next
        Return billnum
    End Function

Please point out if I am wrong.
Posted
Updated 25-Dec-10 19:35pm
v2

You can translate guid into two ulong numbers:
C#
Guid g = Guid.NewGuid();
Byte[] b = g.ToByteArray();
UInt64 u1= BitConverter.ToUInt64(b,0);
UInt64 u2 = BitConverter.ToUInt64(b, 8);
MessageBox.Show(u1.ToString() + u2.ToString());

But those bill numbers are giant and not sorted ... try simply increment and remember your numbers.
 
Share this answer
 
As far as creation of GUID[^] goes, its just:
VB
Dim numGuid As Guid = System.Guid.NewGuid();


Now, this looks ok in your code. But what you have done after that is something you need to explain and look at. It looks like you are just trying to pick numbers from the generated GUID and assign that as bill number. If your intention of doing this was to have a unique bill number always then I am sorry to say so, this implementation/approach is incorrect.

Guid as a whole (with combination of number & string) is unique. Picking only numbers from it will not assure uniqueness.
 
Share this answer
 
Yes i want a unquie number which i want to use as billnumber...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900