View Poll Results: Are these codes written in good programming format?

Voters
2. You may not vote on this poll
  • Yes

    0 0%
  • No

    0 0%
  • kind of

    2 100.00%
  • I don't know

    0 0%
Multiple Choice Poll.
Results 1 to 5 of 5

Thread: [2005] File Search Questions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Arrow [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:
    1. Imports System
    2. Imports System.IO
    3. Imports Microsoft.VisualBasic.ControlChars
    4. Imports System.Windows.Forms
    5.  
    6. Public Class frmMain
    7.  
    8.     Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
    9.         Dim sPath As String = ""
    10.         Dim fbdPath As New FolderBrowserDialog()
    11.         fbdPath.ShowDialog()
    12.  
    13.         With fbdPath
    14.             sPath = .SelectedPath
    15.             lblInitPath.Text = .SelectedPath.ToString
    16.             MsgBox(sPath)
    17.         End With
    18.         GatherFiles(sPath)
    19.     End Sub
    20.  
    21.     Private Sub GatherFiles(ByVal sFilePath As String)
    22.  
    23.         Dim instance As New DirectoryInfo(sFilePath)
    24.         Dim returnValue As FileInfo
    25.         Dim intValue As Integer = 0
    26.  
    27.  
    28.         For Each returnValue In instance.GetFiles("*.pdf", IO.SearchOption.AllDirectories)
    29.             lstFullNames.Items.Add(returnValue.FullName)
    30.             intValue = intValue + 1
    31.         Next returnValue
    32.         lblTotalFiles.Text = intValue.ToString
    33.  
    34.     End Sub
    35.  
    36. End Class
    Last edited by RobDog888; Nov 30th, 2006 at 06:36 PM. Reason: Added [vbcode] tags

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width