Hi All,
I have to admit to have been terrified by the numbers involved in this exercise. It was actually 10.6 million records to update rather than 9.5 million, but close enough. Nobody actually told me how to do it. I was pointed at stuff that really didn't provide answers, so I finally decided to do it the old fashioned way....... What the hell was I worried about? I cut some code in about 30 minutes and it's currently about one hour into execution and about a quarter of the way through. Given that I never have to do this again, I consider this exceptionally fast. Here is my VB code (simples!):
Private Sub ReadShareDays()
Dim Files As Long
Dim theFile() As String
Dim fb As Integer
Dim s1 As String
lblProgress.Visible = True
ReDim theFile(0 To 10000)
Files = 0
s1 = Dir("E:\Alan & Jill\Shares\Share Market Analysis\Daily Prices\*.txt",)
Do While s1 <> ""
Files += 1
theFile(Files - 1) = s1
s1 = Dir()
Loop
ReDim Preserve theFile(0 To Files - 1)
PB1.Maximum = Files
PB1.Step = 10
PB1.Value = 0
For i1 = 1 To Files
ShareDays = 0
ReDim ShareDay(0 To 4000)
s1 = theFile(i1 - 1)
lblProgress.Text = "Reading Share Days - " & GetField(s1, ".")
fb = FreeFile()
FileOpen(fb, "E:\Alan & Jill\Shares\Share Market Analysis\Daily Prices\" & theFile(i1 - 1), OpenMode.Input)
Do While EOF(fb) <> True
s1 = LineInput(fb)
If s1 <> "" Then
ShareDays += 1
With ShareDay(ShareDays - 1)
.theShare = GetField(s1, ",")
.theDate = MakeDate(GetField(s1, ","))
.theOpen = Val(GetField(s1, ","))
.theHigh = Val(GetField(s1, ","))
.theLow = Val(GetField(s1, ","))
.theClose = Val(GetField(s1, ","))
.theVolume = Val(GetField(s1, ","))
End With
End If
Loop
FileClose(fb)
SaveShareDays()
PB1.Value += 1
Application.DoEvents()
Next
ReDim Preserve theShare(0 To Shares - 1)
lblProgress.Visible = False
Application.DoEvents()
End Sub
Private Function MakeDate(theDate As String) As Date
Dim theYear As String
Dim theMonth As String
Dim theDay As String
theYear = Mid(theDate, 1, 4)
theMonth = Mid(theDate, 5, 2)
theDay = Mid(theDate, 7, 2)
MakeDate = CDate(theDay & "/" & theMonth & "/" & theYear)
End Function
Private Sub SaveShareDays()
Dim DBCon As New sqlData
Dim DBCon2 As New sqlData
Dim ShareRec As Long
Dim fb As Integer
fb = FreeFile()
FileOpen(fb, "E:\Alan & Jill\Shares\Share Market Analysis\Daily Prices\ShareDayErrors.csv", OpenMode.Append)
For Each Share In ShareDay
ShareRec = 0
With DBCon
.Query("SELECT RecNum FROM Shares WHERE theCode = '" & Share.theShare & "'")
If .RecordCount > 0 Then
ShareRec = .DBDT.Rows(0)("RecNum")
End If
End With
If ShareRec > 0 Then
With DBCon
.Query("SELECT * FROM ShareDays WHERE theShare = " & CStr(ShareRec) & " AND theDate = '" & Format(Share.theDate, "yyyy-MM-dd") & "'")
If .RecordCount > 0 Then
If .DBDT.Rows(0)("theClose") > 0 Then
Share.theClose = .DBDT.Rows(0)("theClose")
ShareRec = .DBDT.Rows(0)("theShare")
End If
With DBCon2
.Query("UPDATE ShareDays SET theOpen = " & Share.theOpen.ToString & ", theHigh = " & Share.theHigh.ToString & ", theLow = " & Share.theLow & ", theClose = " & Share.theClose & ", Volume = " & Share.theVolume &
"WHERE theDate = '" & Format(Share.theDate, "yyyy-MM-dd") & "' AND theShare = " & CStr(ShareRec))
End With
Else
PrintLine(fb, Format(Share.theDate, "dd/MM/yyyy") & "," & Share.theShare & "," & CStr(Share.theOpen) & "," & CStr(Share.theHigh) & "," & CStr(Share.theLow) & "," & CStr(Share.theClose) & "," & CStr(Share.theVolume))
End If
End With
End If
Next
FileClose(fb)
End Sub