Program runs very slow
Program runs very slow
Program runs very slow
Program runs very slow
Program runs very slow
Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow
Program runs very slow Program runs very slow
Program runs very slow
Go Back  Xtreme Visual Basic Talk > > > Program runs very slow


Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2005, 11:35 PM
Locrum Locrum is offline
Freshman
 
Join Date: Feb 2005
Posts: 41
Question Program runs very slow


My appologies if this is the wrong forum to be placing this thread. I'm having issues with a program I'm working with, and I can't think of anything offhand that would be causing the issues. (Aside from maybe poor coding.) The original code was VB6, and I've bumped it to VB.net.

We get data in from our customers, usually around 2000 files of mixed data. Some AutoCAD drawings, some pdf, some docs. We also receive a list of the data. So, to check to make sure our information is correct, I have a text file that I use as my list, then I search a directory and sub directories for the specifid files... I've thrown in a few things, like copy the files to a new directory, etc. But I think the root of the slowness is in how the files are checked. (I've also got stuff so nested, it makes my head hurt.)

Bear with me, I'm pretty new to this and maybe a solution is completely obvious to someone. I'm not familiar with dealing with files and how all the memory stuff works. I'll post in two parts.

I'd like to be steered in the right direction, and not looking to have it handed to me on a silver platter.

Here's what I've got:

Code:
 	
	Dim strFileNames As String
	Dim blnNoLength As Boolean
	Dim intStringLength As Short
	Dim strPaths(5) As String
	Dim strSearches() As String
	Dim strFound() As String
	Dim strNotFound() As String

    Sub FindFilesAPI(ByRef DirPath As String, ByRef FileSpec As String)
        Dim FindData As WIN32_FIND_DATA
        Dim FindHandle As Integer
        Dim FindNextHandle As Integer
        Dim filestring As String
        Dim FileNameString As String

        DirPath = Trim(DirPath)

        If VB.Right(DirPath, 1) <> "\" Then
            DirPath = DirPath & "\"
        End If

        ' Find the first file in the selected directory

        FindHandle = FindFirstFile(DirPath & FileSpec, FindData)
        If FindHandle <> 0 Then
            If FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
                ' It's a directory
                If VB.Left(FindData.cFileName, 1) <> "." And VB.Left(FindData.cFileName, 2) <> ".." Then
                    filestring = DirPath & Trim(FindData.cFileName) & "\"
                    If List3.Items.Count < 32760 Then
                        List3.Items.Insert(1, filestring)
                    End If
                End If
            Else
                FileNameString = Trim(FindData.cFileName)
                filestring = DirPath & Trim(FindData.cFileName)
                If List1.Items.Count < 32760 Then
                    List1.Items.Add(filestring)
                    List2.Items.Add(FileNameString)
                End If
            End If
        End If

        ' Now loop and find the rest of the files
        If FindHandle <> 0 Then
            Do

                System.Windows.Forms.Application.DoEvents()

                FindNextHandle = FindNextFile(FindHandle, FindData)
                If FindNextHandle <> 0 Then
                    If FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
                        If VB.Left(FindData.cFileName, 1) <> "." And VB.Left(FindData.cFileName, 2) <> ".." Then
                            filestring = DirPath & Trim(FindData.cFileName) & "\"
                            If List3.Items.Count < 32760 Then
                                List3.Items.Insert(1, filestring)
                            End If
                        End If
                    Else
                        FileNameString = Trim(FindData.cFileName)
                        filestring = DirPath & Trim(FindData.cFileName)
                        If List1.Items.Count < 32760 Then
                            List1.Items.Add(filestring)
                            List2.Items.Add(FileNameString)
                        End If
                    End If
                Else
                    Exit Do
                End If
            Loop
        End If

        ' close the handle for FindFirstFile
        Call FindClose(FindHandle)

    End Sub

Last edited by Locrum; 02-03-2005 at 11:54 PM.
Reply With Quote
  #2  
Old 02-03-2005, 11:51 PM
Locrum Locrum is offline
Freshman
 
Join Date: Feb 2005
Posts: 41
Default Second Part

Here's a part I know is all borked. I kept adding things that I wanted, and now it's all a mess. First problem I had was the original list they'd give us of the drawings would sometimes have an added space at the end of the filename on the excel sheet. Since the real file name didn't have a space, it didn't find the file. Trimmed that. THen I had case sensitivity issues. Never found the right solution, but did the best I could. Then I had an issue where the progam was being used to pull .wmf files from our library, but we also had .dwg files of the same name, so I added in a field so I could specify the file extention....(That resulted in me just copying everything in there again and you can see how it just snowballed. Biggest issue I see is how I messed up the case sensitivity. Since I had no control over the file names in the directory, I tried to compensate. Couldn't figure out how to easily make it case insensitive.

Code:
Sub SearchCopy(ByRef strSearch As String)
        Dim C As Integer
        Dim HaveFile As Boolean
        Dim Filetype As String

        HaveFile = False
        For C = 0 To List1.Items.Count

            'Added in check to remove spaces calling the TrimAll function.
            If chkSpaces.Checked = True Then strSearch = TrimAll(strSearch)

            'Added function to limit search based upon file type.
            Filetype = VB.Right(VB6.GetItemString(List2, C), 3)
            If chkExtension.Checked = True Then
                If Filetype = txtExtension.Text Then

                    'Added in check for copy files button, so no copy would occur when not checked.
                    'changed order of syntax, so HaveFile would change prior to copy. This enabled the
                    'file names to be copied to the Not Found file, but not copy the files.

                    If strSearch = VB.Left(VB6.GetItemString(List2, C), Len(strSearch)) Then
                        HaveFile = True
                        If chkCopyFiles.Checked = True Then
                            FileCopy(VB6.GetItemString(List1, C), Dir2.Path & "\" & VB6.GetItemString(List2, C))
                        End If

                    Else
                        'If file was not found, change search string to uppercase and recheck.
                        strSearch = UCase(strSearch)
                        If strSearch = VB.Left(VB6.GetItemString(List2, C), Len(strSearch)) Then
                            HaveFile = True
                            If chkCopyFiles.Checked = True Then
                                FileCopy(VB6.GetItemString(List1, C), Dir2.Path & "\" & VB6.GetItemString(List2, C))
                            End If
                        Else
                            'If file still was not found, then change search string to lowercase and recheck.
                            strSearch = LCase(strSearch)
                            If strSearch = VB.Left(VB6.GetItemString(List2, C), Len(strSearch)) Then
                                HaveFile = True
                                If chkCopyFiles.Checked = True Then
                                    FileCopy(VB6.GetItemString(List1, C), Dir2.Path & "\" & VB6.GetItemString(List2, C))
                                End If

                            End If
                        End If
                    End If
                End If
            Else
                'Matching loop if extension match is not selected.

                'Added in check for copy files button, so no copy would occur when not checked.
                'changed order of syntax, so HaveFile would change prior to copy. This enabled the
                'file names to be copied to the Not Found file, but not copy the files.

                If strSearch = VB.Left(VB6.GetItemString(List2, C), Len(strSearch)) Then
                    HaveFile = True
                    If chkCopyFiles.Checked = True Then
                        FileCopy(VB6.GetItemString(List1, C), Dir2.Path & "\" & VB6.GetItemString(List2, C))
                    End If

                Else
                    'If file was not found, change search string to uppercase and recheck.
                    strSearch = UCase(strSearch)
                    If strSearch = VB.Left(VB6.GetItemString(List2, C), Len(strSearch)) Then
                        HaveFile = True
                        If chkCopyFiles.Checked = True Then
                            FileCopy(VB6.GetItemString(List1, C), Dir2.Path & "\" & VB6.GetItemString(List2, C))
                        End If
                    Else
                        'If file still was not found, then change search string to lowercase and recheck.
                        strSearch = LCase(strSearch)
                        If strSearch = VB.Left(VB6.GetItemString(List2, C), Len(strSearch)) Then
                            HaveFile = True
                            If chkCopyFiles.Checked = True Then
                                FileCopy(VB6.GetItemString(List1, C), Dir2.Path & "\" & VB6.GetItemString(List2, C))
                            End If

                        End If
                    End If
                End If
            End If

        Next C
        If HaveFile = False Then
            PrintLine(4, strSearch)
        End If

    End Sub
Reply With Quote
  #3  
Old 02-10-2005, 04:42 PM
Locrum Locrum is offline
Freshman
 
Join Date: Feb 2005
Posts: 41
Default

Am I not asking the correct questions, or is this too advanced a subject for the forum? I assumed I'd get a responce back that was general, like you're not efficient here, do some research on on such and such method, or your doing too much at once, break this part out into a seperate function, blah blah.

If this isn't the appropriate forum, someone please let me know. Or even better if someone knows of a tutor or instructor in the Pacific NW I could pay for some one on one and talk through some concepts I'd get a ways farther.
Reply With Quote
  #4  
Old 02-10-2005, 05:29 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

By the looks of what has been answered before that shouldn't be too complicated for some, but all that code looks intimidating, not everyone has that much time on their hands. If you want to get it answered you may consider cutting down to the necessary basics and provide more when requested to. You may also want to enclose that code in VB tags instead of CODE tags.
__________________
170 10101010 410 J31^170
Reply With Quote
  #5  
Old 02-11-2005, 09:01 AM
Evets Evets is offline
Newcomer
 
Join Date: Feb 2005
Posts: 20
Default

Locrum,

I have some code that does something similar (I think) so I'm going to post it here and maybe it will give you some ideas.

Disclaimer:
I have never programed in VB6 just .net so I'm not sure how things were done in VB6. Also, not sure if the reason your program is running slow is necessarily related to what your doing here.

Some points to look at:
- This routine simply looks at every file in a given directory and determines if it has extension of .sh or .ksh if so I call another routine that goes in and does some things with the file (I did not include that routine).
- My code uses the System.IO namespace and uses methods from path, Directory, and File classes that make life a lot easier when working with files.
- Also when doing a string compare when case doesn't matter, do the uppercase or lowercase on both sides of the compare. i.e. if mystring1.tolower = mystring2.tolower then
- Ignore the "theTables" reference as that is a dataset I use and has no bearing on the file processing.

Here's my code, hope it gives you some ideas.
Code:
    Private Sub Analyze(ByVal thePath As String, ByVal theTables As shTables)
        Cursor.Current = System.Windows.Forms.Cursors.WaitCursor

        Dim theFile As String
        Dim fileName As String
        Dim fileExt As String

        theTables.Clear()

        For Each theFile In Directory.GetFiles(thePath)
            fileName = Path.GetFileName(theFile)
            fileExt = Path.GetExtension(theFile)

            stsMain.Text = "Processing: " & fileName
            'Determine File Type
            If fileExt.ToLower.Equals(".sh") Or fileExt.ToLower.Equals(".ksh") Then
                'Process the file
                Try
                    ProcessFile(theFile, theTables)
                Catch ex As Exception
                    MessageBox.Show(ex.Message, ex.GetType.Name, MessageBoxButtons.OK)
                End Try
            End If
        Next
        Cursor.Current = System.Windows.Forms.Cursors.Default
        stsMain.Text = "Ready"
    End Sub
Reply With Quote
  #6  
Old 02-11-2005, 01:48 PM
Locrum Locrum is offline
Freshman
 
Join Date: Feb 2005
Posts: 41
Default

Thanks (to you both) for the responses. It's my first time on this forum, and my forum ettiquette in general is rusty. I had hoped I didn't include too much information, however since my knowledge is so limited I had thought that maybe in some of those details I had created issues that I'm not able to understand that might be blatantly obvious to others. I'll attempt to trim it down some for future referanse and I'll see if I can find the "VB" tags for future posts. I was only able to locate the "code" tags in the message editing screen. Thanks for the assistance, I think that gives me a few ideas and a new direction.
Reply With Quote
  #7  
Old 02-11-2005, 02:33 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

You did fine, I was just mentioning a trend I've seen often. When there is a lot of stuff, or stuff that isn't easy to understand at a glance, most people will skip over the question.
As for the VB tags, I think they aren't official tags for some reason or another, but they are awesome. You just do somthing like this:
[VB]
Your code goes here...
[/vb]
And it'll nicely format it for you.
__________________
170 10101010 410 J31^170
Reply With Quote
  #8  
Old 02-11-2005, 03:40 PM
Master007's Avatar
Master007 Master007 is offline
Newcomer
 
Join Date: Dec 2004
Posts: 22
Default

I dont know .NET but in VB 6.0 the UCASE function turns a string to uppercase.

Code:
astring=ucase(astring)

so turn all files read to uppercase and compare with an uppercase string
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Program runs very slow
Program runs very slow
Program runs very slow Program runs very slow
Program runs very slow
Program runs very slow
Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow Program runs very slow
Program runs very slow
Program runs very slow
 
Program runs very slow
Program runs very slow
 
-->