Hi.
I'm a long time asp-developer, but fairly new to VB so I don't know all the trick yet.
My problem:
I'm writing a program that fetches file and directory information from a given drive/location and stores information in an array for further processing. During this procedure the application sometimes freezes and becomes "Not responding". At the end of the function loop, though, it unfreezes and goes back to normal - it seems the freezing occurs when the function becomes too processor intensive.
Sample code:
Private Sub makeTree(Folder)
ProgressBar1.Visible = True
Dim f, Files, SubFolders, fsize, intFl, intStartSearchbs, intLevel
Set f = fso.GetFolder(Folder)
Set Files = f.Files
intFl = 1
intStartSearchbs = 1
If f.Size / 1024 > 1024 Then
fsize = Round((f.Size / 1024 / 1024), 1)
Else
fsize = "0"
End If
Do While Not InStr(intStartSearchbs, Replace(Folder, TestDrive & ":\", ""), "\", 1) = 0
intStartSearchbs = InStr(intStartSearchbs, Replace(Folder, TestDrive & ":\", ""), "\", 1) + 1
intFl = intFl + 1
Loop
intLevel = intFl + 1
filenow = filenow + 1
tree_n(filenow - 1, 1) = Right(Folder, Len(Folder) - InStrRev(Folder, "\", , vbTextCompare))
tree_n(filenow - 1, 2) = fsize
tree_n(filenow - 1, 3) = intFl
tree_n(filenow - 1, 4) = 1
intFl = 1
If Files.Count > 0 Then
For Each File In Files
intStartSearchbs = 1
intFl = 0
If File.Size / 1024 > 1024 Then
fsize = Round((File.Size / 1024 / 1024), 1)
Else
fsize = "0"
End If
If intLevel = "" Then intLevel = 1
filenow = filenow + 1
tree_n(filenow - 1, 1) = Replace(File, TestDrive & ":\", "")
tree_n(filenow - 1, 2) = fsize
tree_n(filenow - 1, 3) = intLevel
moveOn:
intProgress = Int(100 - Int((filecount - filenow) / filecount * 100))
ProgressBar1.Value = intProgress
currentAction.Refresh
ProgressBar1.Refresh
End If
Next
End If
intFl = 1
Set SubFolders = f.SubFolders
If SubFolders.Count > 0 Then
For Each SubFolder In SubFolders
makeTree (SubFolder.Path)
Next
End If
End Sub
So...how do I make the function loop run without freezing the form (and the progressbar), so the user doesn't think the program crashed??
madmital