View Poll Results: Are these codes written in good programming format?
- Voters
- 2. You may not vote on this poll
-
Yes
-
No
-
kind of
-
I don't know
-
Nov 30th, 2006, 06:12 PM
#1
Thread Starter
Junior Member
[2005] File Search Questions
After much reading of many many post here and the help files in VB express, I have the following codes and would like to know if you think the 'directory' and 'file' methods are better than the 'directoryinfo' and 'fileinfo' I used.
Also, I tried to update the lblTotalFiles and lstFullNames as I stepped through but instead it waited until the end and populated all at once. Why is that?
VB Code:
Imports System
Imports System.IO
Imports Microsoft.VisualBasic.ControlChars
Imports System.Windows.Forms
Public Class frmMain
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
Dim sPath As String = ""
Dim fbdPath As New FolderBrowserDialog()
fbdPath.ShowDialog()
With fbdPath
sPath = .SelectedPath
lblInitPath.Text = .SelectedPath.ToString
MsgBox(sPath)
End With
GatherFiles(sPath)
End Sub
Private Sub GatherFiles(ByVal sFilePath As String)
Dim instance As New DirectoryInfo(sFilePath)
Dim returnValue As FileInfo
Dim intValue As Integer = 0
For Each returnValue In instance.GetFiles("*.pdf", IO.SearchOption.AllDirectories)
lstFullNames.Items.Add(returnValue.FullName)
intValue = intValue + 1
Next returnValue
lblTotalFiles.Text = intValue.ToString
End Sub
End Class
Last edited by RobDog888; Nov 30th, 2006 at 06:36 PM.
Reason: Added [vbcode] tags
-
Nov 30th, 2006, 06:23 PM
#2
Re: [2005] File Search Questions
If all you need are the names of the files and folders then you should use the File and Directory classes because they don't require instances to be created. There's no point creating FileInfo and DirectoryInfo objects when they aren't required.
The reason that your UI doesn't update until the end is that the process is too busy doing the searching to redraw the controls. You may want to think about using a BackgroundWorker to perform the long-running operation.
Also, take a look at your post after you submit it to make sure it looks OK. You could have easily gone back and edited your incorrect VBCODE tags.
-
Nov 30th, 2006, 06:37 PM
#3
Re: [2005] File Search Questions
Its ok, I updated the post and corrected the vbcode tags. Looks so much better now.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 4th, 2006, 08:44 PM
#4
Thread Starter
Junior Member
Re: [2005] File Search Questions
So what do you mean a background worker? Should I have a progress bar running and then when finished processing then show the results?
-
Dec 4th, 2006, 09:03 PM
#5
Re: [2005] File Search Questions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|