Dim myRnd As String
'--- 乱数初期化
Randomize(Double.Parse(Format(Now(), "hhmmssfff"))) 'fffはミリ秒3桁
'4桁の乱数を作成
For x = 1 To 4
'0~9の範囲の乱数を取得して文字列として結合
myRnd = myRnd & CStr(Int((9 - 0 + 1) * Rnd() + 0))
Next x
Dim strRes As String = "ABC-" & Format(CType(Now, Date), "yyyyMMddHHmmssfff") & "-" & myRnd
strRes → ABC-20190121150037123-5678
a b c d e
-a → "ABC-" 固定値
-b → "20190121" 日付
-c → "150037" 時刻
-d → "123" ミリ秒
-e → "5678" 乱数
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme