Public Sub CreateUserTable()
Dim fso As New Scripting.FileSystemObject
Dim userStream As Scripting.TextStream
Dim dataStream As Scripting.TextStream
Dim pFuncs As WorksheetFunction, sDate As String
Dim sUser As String, i As Long, k As Long
Dim bStr(0 To 31) As Byte
Set userStream = fso.CreateTextFile("c:\temp\user.csv", True)
Set dataStream = fso.CreateTextFile("c:\temp\data.csv", True)
Set pFuncs = Application.WorksheetFunction
userStream.WriteLine "UserName,UserBirthday"
dataStream.WriteLine "UserName,DateBuy,Amount"
For i = 1 To 2000000
For k = 0 To 31 Step 2
bStr(k) = CByte(pFuncs.RandBetween(33, 96))
Next
sUser = bStr
sUser = Replace$(sUser, ",", "_"): sUser = Replace$(sUser, """", "_")
sDate = Format$(DateSerial(CInt(pFuncs.RandBetween(1930, 2010)), CInt(pFuncs.RandBetween(1, 12)), CInt(pFuncs.RandBetween(1, 28))), "dd.mm.yyyy")
userStream.WriteLine sUser & "," & sDate
For k = 1 To CLng(pFuncs.RandBetween(3, 9))
sDate = Format$(DateSerial(CInt(pFuncs.RandBetween(1960, 2015)), CInt(pFuncs.RandBetween(1, 12)), CInt(pFuncs.RandBetween(1, 28))), "dd.mm.yyyy")
dataStream.WriteLine sUser & "," & _
sDate & "," & _
Format$(1000# * Rnd, "0.00")
Next
If (i Mod 10000) = 0 Then
DoEvents
Debug.Print i
End If
Next
dataStream.Close: userStream.Close
MsgBox "end"
End Sub
Public Sub AddNotIn()
Dim fso As New Scripting.FileSystemObject
Dim userStream As Scripting.TextStream
Dim dataStream As Scripting.TextStream
Dim pFuncs As WorksheetFunction, sDate As String
Dim sUser As String, i As Long, k As Long
Set pFuncs = Application.WorksheetFunction
Set dataStream = fso.OpenTextFile("c:\temp\data.csv", ForAppending)
For i = 1 To 500000
sUser = ""
For k = 1 To 16
sUser = sUser & Chr(CLng(pFuncs.RandBetween(183, 255)))
Next
For k = 1 To CLng(pFuncs.RandBetween(4, 9))
sDate = Format$(DateSerial(CInt(pFuncs.RandBetween(1960, 2015)), CInt(pFuncs.RandBetween(1, 12)), CInt(pFuncs.RandBetween(1, 28))), "dd.mm.yyyy")
dataStream.WriteLine sUser & "," & _
sDate & "," & _
Format$(1000# * Rnd, "0.00")
Next
If (i Mod 10000) = 0 Then
DoEvents
Debug.Print i
End If
Next
dataStream.Close
End Sub
|