Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How create a unique file name in VB 6? 1

Status
Not open for further replies.

cl8855

Programmer
Nov 28, 2000
47
US
The search is down, so I will just start a new thread -

How can I create a unique file name within VB 6.0? On other platforms we just use a timestamp down to milliseconds, but the time function doesn't go that far on VB 6.0. Anyone have a way around the timestamp and/or a way to create a unique name every time (across multiple users and application executions!)

thanks,
 
It's not the HRESULT you should worry about, this is just a long integer for you (it will return 0 on success and otherwise on failure).

You should worry more about the GUID structure (which is not a native VB datatype):

typedef struct _GUID
{
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[8];
} GUID;

which should be something like:
long
integer
integer
byte(7)




Greetings,
Rick
 
Er, vb5prgrmr my comment specifically concerned GetSystemTime, not the QueryPerformance family which do not suffer from the same problem.
 
In case anyone else wants my solution - thanks to all (and code from the web!)

Private Declare Function CoCreateGuid Lib "ole32" (id As Any) As Long

Public Function CreateGUID() As String
Dim id(0 To 15) As Byte
Dim Cnt As Long, GUID As String
If CoCreateGuid(id(0)) = 0 Then
For Cnt = 0 To 15
CreateGUID = CreateGUID + IIf(id(Cnt) < 16, &quot;0&quot;, &quot;&quot;) + Hex$(id(Cnt))
Next Cnt
CreateGUID = Left$(CreateGUID, 8) + Mid$(CreateGUID, 9, 4) + Mid$(CreateGUID, 13, 4) + Mid$(CreateGUID, 17, 4) +Right$(CreateGUID, 12)
Else
MsgBox &quot;Error while creating GUID!&quot;
End If
End Function

Dim thisUniqueFile as String
thisUniqueFile = CreateGUID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top