私はVB.NETの世界に不慣れで、約2000のExcelスプレッドシートのディレクトリを検索する小さなプログラムをまとめ、そのスプレッドシートファイル内のカスタムドキュメントプロパティの値に基づいて表示するリストをまとめるという任務を負っています。私が教育や貿易でコンピュータープログラマーから遠く離れていることを考えると、これは冒険でした。
私はそれを機能させました、結果は素晴らしいです。問題は、実行に1分以上かかることです。LAN接続で実行されています。ローカルで実行すると(約300ファイルの「test」ディレクトリを使用)、約4秒で実行されます。
妥当な実行速度として何が期待できるのかわからないので、ここで聞いてみようと思いました。
コードは以下のとおりです。誰かが変更を考えた場合、物事をスピードアップするのに役立つかもしれません。
前もって感謝します!
Private Sub listByPt()
Dim di As New IO.DirectoryInfo(dir_loc)
Dim aryFiles As IO.FileInfo() = di.GetFiles("*" & ext_to_check)
Dim fi As IO.FileInfo
Dim dso As DSOFile.OleDocumentProperties
Dim sfilename As String
Dim sheetInfo As Object
Dim sfileCount As String
Dim ifilesDone As Integer
Dim errorList As New ArrayList()
Dim ErrorFile As Object
Dim ErrorMessage As String
'Initialize progress bar values
ifilesDone = 0
sfileCount = di.GetFiles("*" & ext_to_check).Length
Me.lblHighProgress.Text = sfileCount
Me.lblLowProgress.Text = 0
With Me.progressMain
.Maximum = di.GetFiles("*" & ext_to_check).Length
.Minimum = 0
.Value = 0
End With
'Loop through all files in the search directory
For Each fi In aryFiles
dso = New DSOFile.OleDocumentProperties
sfilename = fi.FullName
Try
dso.Open(sfilename, True)
'grab the PT Initials off of the logsheet
Catch excep As Runtime.InteropServices.COMException
errorList.Add(sfilename)
End Try
Try
sheetInfo = dso.CustomProperties("PTNameChecker").Value
Catch ex As Runtime.InteropServices.COMException
sheetInfo = "NONE"
End Try
'Check to see if the initials on the log sheet
'match those we are searching for
If sheetInfo = lstInitials.SelectedValue Then
Dim logsheet As New LogSheet
logsheet.PTInitials = sheetInfo
logsheet.FileName = sfilename
PTFiles.Add(logsheet)
End If
'update progress bar
Me.progressMain.Increment(1)
ifilesDone = ifilesDone + 1
lblLowProgress.Text = ifilesDone
dso.Close()
Next
lstResults.Items.Clear()
'loop through results in the PTFiles list
'add results to the listbox, removing the path info
For Each showsheet As LogSheet In PTFiles
lstResults.Items.Add(Path.GetFileNameWithoutExtension(showsheet.FileName))
Next
'build error message to display to user
ErrorMessage = ""
For Each ErrorFile In errorList
ErrorMessage += ErrorFile & vbCrLf
Next
MsgBox("The following Log Sheets were unable to be checked" _
& vbCrLf & ErrorMessage)
PTFiles.Clear() 'empty PTFiles for next use
End Sub