|
-
Oct 4th, 2000, 08:24 PM
#1
Thread Starter
New Member
Will somebody please help a newbie create unique numbers in VB6, hopefully using DateTime stripped of non-numeric characters?
Any help gratefully accepted.
Patrick
VB6 Ent SP3
(tis better to light a candle than rail against the darkness)
-
Oct 4th, 2000, 10:30 PM
#2
Do you mean stripping a Date-Time Var clean of non-num chars?
Code:
Function Strip(DateTime as Date) As Long
Dim s, i, t, ss
s = Str(DateTime)
For i = 1 To Len(s)
t = Mid(s, i, 1)
If Not IsNumeric(t) then t = ""
ss = ss + t
Next
Strip = Int(ss)
End Function
-
Oct 4th, 2000, 11:22 PM
#3
Fanatic Member
Or to create random(unique) numbers:
Code:
Text1.Text = Int(Rnd * 1000)
Gl,
D!m
-
Oct 5th, 2000, 04:38 AM
#4
Try this code: It creates a GLOBAL UNIQUE IDENTIFIER (which should be always unique ... in the world(!) )...
Create a new project and add a command-button and a Label
Paste this code
Code:
Option Explicit
Private Type GUIDType
D1 As Long
D2 As Integer
D3 As Integer
D4(8) As Byte
End Type
Private Declare Function WinCoCreateGuid Lib "OLE32.DLL" Alias "CoCreateGuid" (g As GUIDType) As Long
Public Function CreateGUIDString() As String
Dim g As GUIDType
Dim sBuf As String
Call WinCoCreateGuid(g)
sBuf = _
PadZeros(Hex$(g.D1), 8, True) & _
PadZeros(Hex$(g.D2), 4, True) & _
PadZeros(Hex$(g.D3), 4, True) & _
PadZeros(Hex$(g.D4(0)), 2) & _
PadZeros(Hex$(g.D4(1)), 2, True) & _
PadZeros(Hex$(g.D4(2)), 2) & _
PadZeros(Hex$(g.D4(3)), 2) & _
PadZeros(Hex$(g.D4(4)), 2) & _
PadZeros(Hex$(g.D4(5)), 2) & _
PadZeros(Hex$(g.D4(6)), 2) & _
PadZeros(Hex$(g.D4(7)), 2)
CreateGUIDString = sBuf
End Function
Private Function PadZeros(ByVal sBit As String, ByVal iStrLen As Integer, Optional bHyphen As Boolean) As String
If iStrLen > Len(sBit) Then
sBit = Right$(String$((iStrLen - Len(sBit)), "0") & sBit, iStrLen)
End If
If bHyphen Then sBit = sBit & "-"
PadZeros = sBit
End Function
Private Sub Command1_Click()
Label1.Caption = CreateGUIDString
End Sub
Enjoy!
-
Oct 5th, 2000, 05:49 AM
#5
Fanatic Member
For trouble ticket systems I wrote in ASP once upon a time I used
round(Cdbl(NOW()) * 100000,0)
so you could trace the ticket back to the time it was created.
or if user load is high then multiply by 10,000,000 so you get 1000 per second rather than 10
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Oct 6th, 2000, 07:42 PM
#6
Guys.
He told me, by e-mail, that he had already solved the problem. He does mean what I thought, and He used Format(now, "MMddyyhhmmss") and solved it. We should stop trying to overcrowd VB-World [JOKE].
He solved it, so it saves energy to stop .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|