Gustav Brock
Gustav at cactus.dk
Fri Sep 29 06:36:34 CDT 2006
Hi Martin
I guess you need a GUID in its string representation.
We use this function which (or similar) is quite common.
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare Function CoCreateGuid Lib "ole32.dll" ( _
ByRef pguid As GUID) As Long
Private Declare Function StringFromGUID2 Lib "ole32.dll" ( _
ByRef rguid As Any, _
ByVal lpstrClsId As Long, _
ByVal cbMax As Long) As Long
Public Function GetGUIDString() As String
' Create a GUID and return its string representation.
'
' 2002-12-15. Cactus Data ApS, CPH.
' Length of GUID string per definition.
Const clngGUID As Long = 38
' Length of buffer with added space for zero terminator.
Const clngBuffer As Long = clngGUID + 1
Dim udtGuid As GUID
Dim strGUID As String * clngGUID
Dim abytGUID() As Byte
' Dim byte array.
abytGUID() = String(clngBuffer, vbNullChar)
' Create GUID.
If CoCreateGuid(udtGuid) = 0 Then
' GUID was successfully created.
If StringFromGUID2(udtGuid, VarPtr(abytGUID(0)), clngBuffer) = clngBuffer Then
' GUID was successfully copied into byte array abytGUID in Unicode.
' Convert byte array to Ansi GUID string stripping zero terminator.
strGUID = abytGUID
End If
End If
GetGUIDString = strGUID
End Function
As Marty tells, those GUIDs will always contain 4 at position 13. You may set off from the crowd by replacing this char with something else.
/gustav
>>> mwp.reid at qub.ac.uk 28-09-2006 21:52:32 >>>
Havnt needed this much help in some time
I am doing an update to a system table. The table has a PK of ReplicationID Data type number.
The insert includes some of the XML stuff I posted earlier. The new issue is when you run the wizard the insert happens by magic including the GUID PK.
How can I create this GUID via CODE?
Martin
Martin WP Reid
Training and Assessment Unit
Riddle Hall
Belfast
tel: 02890 974477