Private
Sub
frmTransPenjualanBaru_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
RandomCharAndNum()
End
Sub
Private
Sub
RandomCharAndNum()
Dim
tahun = Format(
CDate
(DateAndTime.Now),
"yMMddhhss"
)
TextBox1.Text = RandomString(4, _chars) & tahun & RandomString(2, _nums)
End
Sub
Private
Const
_chars
As
String
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private
Const
_nums
As
String
=
"0123456789"
Private
Shared
ReadOnly
_randLock =
New
Object
()
Private
Shared
ReadOnly
_rnd =
New
Random()
Private
Shared
Function
RandomString(
ByVal
size
As
Integer
,
ByVal
chars
As
String
)
As
String
Dim
arr =
New
Char
(size - 1) {}
For
i
As
Integer
= 0
To
size - 1
SyncLock
_randLock
arr(i) = chars(_rnd.
Next
(chars.Length))
End
SyncLock
Next
Return
New
String
(arr)
End
Function
No comments:
Post a Comment