Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2003, 09:45 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Thumbs up How get the GUID automaticly?

I will Creates a Genuinely Unique Identification Number (GUID) of type, like {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}.
__________________
Being a Code Headman !

Reply With Quote
  #2  
Old October 21st, 2003, 10:55 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
This function creates a globally unique identifier (GUID), such as the ones used in the Windows registry to identify COM objects. Useful anytime you need a unique identifier, e.g., an ID field in a database table

sample:
Private Type GUID
PartOne As Long
PartTwo As Integer
PartThree As Integer
PartFour(7) As Byte
End Type

Private Declare Function CoCreateGuid Lib "OLE32.DLL" _
(ptrGuid As GUID) As Long

'RETURNS: GUID if successful; blank string otherwise.
'Unlike the GUIDS in the registry, this function returns GUID
'without "-" characters. See comments for how to modify if you
'want the dash.

Public Function GUID() As String
Dim lRetVal As Long
Dim udtGuid As GUID

Dim sPartOne As String
Dim sPartTwo As String
Dim sPartThree As String
Dim sPartFour As String
Dim iDataLen As Integer
Dim iStrLen As Integer
Dim iCtr As Integer
Dim sAns As String

On Error GoTo errorhandler
sAns = ""

lRetVal = CoCreateGuid(udtGuid)

If lRetVal = 0 Then

'First 8 chars
sPartOne = Hex$(udtGuid.PartOne)
iStrLen = Len(sPartOne)
iDataLen = Len(udtGuid.PartOne)
sPartOne = String((iDataLen * 2) - iStrLen, "0") _
& Trim$(sPartOne)

'Next 4 Chars
sPartTwo = Hex$(udtGuid.PartTwo)
iStrLen = Len(sPartTwo)
iDataLen = Len(udtGuid.PartTwo)
sPartTwo = String((iDataLen * 2) - iStrLen, "0") _
& Trim$(sPartTwo)

'Next 4 Chars
sPartThree = Hex$(udtGuid.PartThree)
iStrLen = Len(sPartThree)
iDataLen = Len(udtGuid.PartThree)
sPartThree = String((iDataLen * 2) - iStrLen, "0") _
& Trim$(sPartThree) 'Next 2 bytes (4 hex digits)

'Final 16 chars
For iCtr = 0 To 7
sPartFour = sPartFour & _
Format$(Hex$(udtGuid.PartFour(iCtr)), "00")
Next

'To create GUID with "-", change line below to:
'sAns = sPartOne & "-" & sPartTwo & "-" & sPartThree _
'& "-" & sPartFour

sAns = sPartOne & sPartTwo & sPartThree & sPartFour

End If

GUID = sAns
Exit Function


errorhandler:
'return a blank string if there's an error
Exit Function
End Function

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How get the GUID automaticly?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway