Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,267 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,173 people online right now. Registration is fast and FREE... Join Now!




How do I Avoid Slow Word Processing?

 
Reply to this topicStart new topic

How do I Avoid Slow Word Processing?, Bloat and 10,000 + lines of text

mjsmikey
6 Jan, 2009 - 04:35 AM
Post #1

New D.I.C Head
*

Joined: 18 Dec, 2008
Posts: 16

I have been trying to process some text documents of 15,000 lines or so. I wrote a program that reads line by line and copies characters if a string is present.

The Code works but when I input 10,000 lines or more of text the Computer uses 50% of the computing power, but only intermittently like --- --- --- Use --- --- --- Use --- ---, where each --- dash represents 0.5 seconds.

I don't know if I should use some sort of Dim as long feature, as I'm not really sure what this does and what it would mean to use it. It seems to be BLOATING... but I'm not really sure.

Is there a code for telling the Process that the document about to be processed is really long, so that it doesn't take 10 minutes to process a 15,000 line document, and might use the processor like Use Use Use Use Use... etc?

Any Help would be appreciated

Thanks,
Mike


User is offlineProfile CardPM
+Quote Post


mjsmikey
RE: How Do I Avoid Slow Word Processing?
6 Jan, 2009 - 04:50 AM
Post #2

New D.I.C Head
*

Joined: 18 Dec, 2008
Posts: 16

Here is the code I am using for any questions.
CODE

Private Sub Strip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Strip.Click
        RichTextBox1.Text = String.Empty
        MsgBox("THIS MAY TAKE SOME TIME - MAY EVEN SHOW NOT RESPONDING - JUST WAIT - YOU CAN CONTINUE TO WORK WHILE THIS IS RUNNING", vbOKCancel)
        RichTextBox1.Text &= "(THIS DOCUMENT HAS BEEN MODIFIED WITH STRIP-N-SAVE)" & vbNewLine
        'Correcting Blank Values on Form
        If TextBox5.Text = "" Then
            TextBox5.Text = "50"
        End If
        If TextBox4.Text = "" Then
            TextBox4.Text = "20"
        End If
        If TextBox3.Text = "" Then
            TextBox3.Text = "20"
        End If
        If TextBox1.Text = "" Then
            TextBox1.Text = "M6"
        End If
        If TextBox2.Text = "" Then
            TextBox2.Text = TextBox1.Text
        End If

        'Variables
        Dim endLine = CInt(TextBox5.Text)
        Dim LineCount As Integer = Document.Lines.Length
        Dim randarray(0 To LineCount) As Long
        ProgressBar1.Maximum = UBound(randarray)
        Dim StartLine = CInt(TextBox3.Text)
        Dim Ending = CInt(TextBox4.Text)
        'Correcting Input if Document too Short
        If LineCount < endLine - 1 Then
            endLine = LineCount
        End If
        'Coping First Lines At all times
        For x As Integer = 0 To endLine - 1
            RichTextBox1.Text &= Document.Lines(x) & vbNewLine
            ProgressBar1.Value = x
        Next
        'Search For Text and Copy if Exists
        For x As Integer = endLine To LineCount - 1
            If Document.Lines(x).Contains(TextBox1.Text) Or Document.Lines(x).Contains(TextBox2.Text) Then
                If LineCount <= x + Ending Then
                    Ending = 10
                End If
                If LineCount <= x + Ending Then
                    Ending = 5
                End If
                If LineCount <= x + Ending Then
                    Ending = 1
                End If
                If LineCount <= x + Ending Then
                    Ending = 0
                End If
                If LineCount <= x + Ending Then
                    Exit For
                End If
                For k As Integer = x - StartLine To x + Ending
                    RichTextBox1.Text &= Document.Lines(k) & vbNewLine
                    If LineCount <= k Then
                        Exit For
                    End If

                Next
                x = x + Ending
                ProgressBar1.Value = x
                'Stop if Document is Too Short
                If x >= LineCount - 1 Then
                    Exit For
                End If
            Else
                If x >= LineCount - 1 Then
                    Exit For
                End If
            End If
            'Stop if Document is Too Short
            If x >= LineCount - 1 Then
                Exit For
            End If
        Next
        ProgressBar1.Value = LineCount
        MsgBox("Document Complete - Press Save", vbOKCancel)

    End Sub

User is offlineProfile CardPM
+Quote Post

mjsmikey
RE: How Do I Avoid Slow Word Processing?
6 Jan, 2009 - 05:31 AM
Post #3

New D.I.C Head
*

Joined: 18 Dec, 2008
Posts: 16

OK... so my research tells me I probably should be using StringBuilder but... I'm not really sure how to incorporate it into this.

I know I add
CODE
dim NewStringBuilder As New System.Text.StringBuilder

but what do I change
CODE
RichTextBox1.Text &= Document.Lines(x) & vbNewLine

to?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 12:42PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month