Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27350

VS 2010 Streamreader not reading all lines

$
0
0
Hey Guys,

I can't figure this one out, when i setup my streamreader to read a bunch of urls over 1000 long it only shows in the listbox 200+

My Code:

Code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click

        Try

            '// Open the target file...
            OpenFileDialog1.Title = "Select accounts file..."
            OpenFileDialog1.InitialDirectory = "C:"
            OpenFileDialog1.ShowDialog()

            '// Display the file in the input area...
            txtBoxInput.Text = OpenFileDialog1.FileName.ToString()

            '// List ready to use...
            Dim list As New List(Of String)

            '// Open file with the Using statement.
            Using sReader As StreamReader = New StreamReader(OpenFileDialog1.FileName)

                '// Loop over each line in file, While list is Not Nothing.
                Do While sReader.Peek <> -1

                    '// Store the read content in here...
                    Dim line As String

                    '// Read first line.
                    line = sReader.ReadLine

                    '// Add this line to list.
                    list.Add(line)

                    '// Add contents to list box.
                    listBoxMain.Items.Add(sReader.ReadLine)

                    '// Feed each account to the function form fixing...
                    Dim lineFixed As String = fixAccountFile(sReader.ReadLine)

                    '// Read in the next line.
                    line = sReader.ReadLine

                    '// Add to the saved listbox...
                    listBoxSaved.Items.Add(lineFixed)

                Loop

                '// Show the count...
                lblCount.Text = listBoxSaved.Items.Count & " Accounts have been formatted."
                lblCount.ForeColor = Color.Green

                '// Close up the streamreader
                sReader.Close()

            End Using

        Catch ex As Exception

            MessageBox.Show(ex.ToString)

        End Try


    End Sub

And the function used in the code:

Code:

    Function fixAccountFile(ByVal strAccount)

        '// First split the HOST/USERNAME/PASSWORD
        Dim stringArray As String() = strAccount.Split(" ")
        Dim stringURI As String
        Dim stringUser As String
        Dim stringPass As String
        Dim newURL As String

        stringURI = stringArray(0)
        stringUser = stringArray(1)
        stringPass = stringArray(2)

        '// The fix for the "?q=" sites...
        If (stringURI.Contains("?q=")) Then

            '// Begin the clean up...
            Dim theStringUrl = stringURI
            Dim theUri = New Uri(theStringUrl)
            Dim theDomain = theUri.GetLeftPart(UriPartial.Authority)

            '// Rebuilt URL...
            newURL = theDomain & "/?q=user/login&destination=node/add " & stringArray(1) & " " & stringArray(2)

            'MessageBox.Show(newURL)

            'Return newURL

        Else

            '// Begin the clean up...
            Dim theStringUrl = stringURI
            Dim theUri = New Uri(theStringUrl)
            Dim theDomain = theUri.GetLeftPart(UriPartial.Authority)

            '// Rebuilt URL...
            newURL = theDomain & "/user/login?destination=node/add " & stringArray(1) & " " & stringArray(2)

            'MessageBox.Show(newURL)

            'Return newURL

        End If

        Return newURL


        'MessageBox.Show(theDomain)

    End Function

it reads and formats just a couple of hundred with no errors, is htere something i am missing? :)

thanks for any help guys

Graham

Viewing all articles
Browse latest Browse all 27350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>