i am new in vb. I am trying to develop a program which scan files and raise event when new file begin but i got a warning message invalid case exception was unhandled.
following is the code
thanks in advance
Imports System.IO
Imports System.IO.Directory
Public Class DirScanner
Public Event ScanProgress(ByVal foldersScanned As Integer)
Private totalSize As Long
Private nFolders As String
Public Function ScanFolder(ByVal folder As Integer)
Dim file, dir As String
Dim FI As FileInfo
For Each file In Directory.GetFiles(folder)
FI = New FileInfo(file)
totalSize = totalSize + FI.Length
Next
For Each dir In Directory.GetDirectoryRoot(folder)
nFolders = nFolders + 1
RaiseEvent ScanProgress(nFolders)
ScanFolder(dir)
Next
Return totalSize
End Function
End Class
Public Class Form1
Dim WithEvents objDirScanner As DirScanner
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folder As String
objDirScanner = New DirScanner()
folder = "C:\Program files"
MsgBox("Your files occupy " & objDirScanner.ScanFolder(folder).ToString & " bytes on the drive")
End Sub
Private Sub objDirScanner_ScanProgress(ByVal foldersScanned As Integer) Handles objDirScanner.ScanProgress
Me.Text = "Scanned" & foldersScanned.ToString & " folders so far"
End Sub
End Class
following is the code
thanks in advance
Imports System.IO
Imports System.IO.Directory
Public Class DirScanner
Public Event ScanProgress(ByVal foldersScanned As Integer)
Private totalSize As Long
Private nFolders As String
Public Function ScanFolder(ByVal folder As Integer)
Dim file, dir As String
Dim FI As FileInfo
For Each file In Directory.GetFiles(folder)
FI = New FileInfo(file)
totalSize = totalSize + FI.Length
Next
For Each dir In Directory.GetDirectoryRoot(folder)
nFolders = nFolders + 1
RaiseEvent ScanProgress(nFolders)
ScanFolder(dir)
Next
Return totalSize
End Function
End Class
Public Class Form1
Dim WithEvents objDirScanner As DirScanner
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folder As String
objDirScanner = New DirScanner()
folder = "C:\Program files"
MsgBox("Your files occupy " & objDirScanner.ScanFolder(folder).ToString & " bytes on the drive")
End Sub
Private Sub objDirScanner_ScanProgress(ByVal foldersScanned As Integer) Handles objDirScanner.ScanProgress
Me.Text = "Scanned" & foldersScanned.ToString & " folders so far"
End Sub
End Class