Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a reorg for .NET Framework 4
Message
From
23/07/2010 06:34:13
 
 
To
22/07/2010 18:03:04
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01473537
Message ID:
01473570
Views:
56
>This code used to run extremely fast before I moved to .NET Framework 4.
>
>
>        ' Return the specific line in a string
>        ' expN1 Line
>        Public Function MLine(ByVal tnLine As Integer) As Boolean
>            Dim lnLocation As Integer = 0
>            Dim loStringBuilderValueAdjusted As StringBuilder = New StringBuilder()
>
>            ' If the line requested is greather than the number of lines
>            If tnLine > nLine Then
>                cLine = ""
>                Return True
>            End If
>
>            ' If we are requesting the first ilne
>            If tnLine = 1 Then
>
>                ' See if we have more than one line
>                If nLine > 1 Then
>                    cLine = Mid(oStringBuilder.ToString, 1, InStr(oStringBuilder.ToString, oApp.cCR) - 1)
>                Else
>                    cLine = oStringBuilder.ToString
>                End If
>
>            Else
>
>                ' Make sure we are able to find a carriage return
>                lnLocation = oApp.At(oApp.cCR, oStringBuilder.ToString, tnLine - 1)
>                If lnLocation > 0 Then
>                    loStringBuilderValueAdjusted.Append(Mid(oStringBuilder.ToString, _
>                     oApp.At(oApp.cCR, oStringBuilder.ToString, tnLine - 1) + 2))
>
>                    ' If this is not the last line
>                    lnLocation = InStr(loStringBuilderValueAdjusted.ToString, oApp.cCR)
>                    If lnLocation > 0 Then
>                        cLine = Mid(loStringBuilderValueAdjusted.ToString, 1, _
>                         InStr(loStringBuilderValueAdjusted.ToString, oApp.cCR) - 1)
>                    Else
>                        cLine = loStringBuilderValueAdjusted.ToString
>                    End If
>
>                Else
>                    cLine = oStringBuilder.ToString
>                End If
>            End If
>
>            Return True
>        End Function
>
>
>Basically, this code returns a specific line from a string. It was originally designed to match the MLine() function of VFP. But, now, under the .NET Framework 4.0, this runs extremely slow. The greater the number of lines in the string, the more the duration in time it takes to find the line.
>
>So, basically, I read a directory having 1000 files. This goes into a string. Then, I use the number of carriage returns to locate the start of the string and get the line associated to it. But, I have to find another approach. Does anyone would have a better function to return a specific line from a string?


(1) You are constructing a StringBuilder each time you want a line. Can you work on the string directly ?
(2) I suspect the At() takes a long time - especially if you want the 900th line or so
(3) Instead of reading the directory into one string, can you read it into an array or strings ? That way the access to any line would be fast and you would not have the overhead of splitting each time you want a specific line
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform