.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 4th, 2008, 12:08 PM
smelf1 smelf1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 11 smelf1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 19 m 22 sec
Reputation Power: 0
Help with reading file to buffer & sending

Hi,

I want to read the text file and put each line into a buffer before i send it to the 2nd listbox. Can anyone check out the code and point me in the right direction.

Code:
Public Class Form1
    Dim line As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Reads contents of c:\encrypt.txt
        Dim fileContents() As String = System.IO.File.ReadAllLines("C:\message.txt")
        For i As Integer = 0 To fileContents.GetUpperBound(0)
            fileContents(i) = System.IO.Path.GetFileNameWithoutExtension(fileContents(i))
            ' ListBox1.Items.Add(fileContents(i))
            If i Mod 2 = 0 Then
                ListBox1.Items.Add(fileContents(i))
            Else
                ListBox2.Items.Add(fileContents(i))
            End If
        Next

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim i As Integer

        For i = 0 To ListBox1.Items.Count - 1
            ProgressBar1.Maximum = ListBox1.Items.Count - 1
            ProgressBar1.Step = 1
            ListBox1.Items.Clear()
            Dim myfile = ListBox1.Items(i)
            Dim mystream As New IO.FileStream(myfile, IO.FileMode.Open, IO.FileAccess.Read) ' Create a new file stream to hold the contents of the file 
            Dim sr As New IO.StreamReader(mystream) ' Use SR to read our new stream 
            Dim buffer As String = Nothing ' Used as a temporary holder 

            Do While sr.EndOfStream = False ' Do the loop until we have reached the end of the file 

                buffer = sr.ReadLine ' Throw the line into buffer 

                If buffer <> Nothing And buffer.StartsWith("#") Then ' If buffer is not a blank line or does not start with @

                    ListBox2.Items.Add(buffer + " " + (System.Text.RegularExpressions.Regex.Match(buffer, "(\w+)").Groups(1).ToString()))
                Else
                    ListBox2.Items.Add(buffer)
                End If

            Loop

            sr.Close() ' Close the stream reader. 
            mystream.Close() ' Close the stream. 

            Dim i1 As Integer
            Dim s As String

            If ListBox1.Items.Count > 0 Then
                Dim file As New System.IO.StreamWriter(ListBox1.Items.Item(i).ToString + "c:\sendmessage.txt", True, System.Text.Encoding.UTF8)
                For i1 = 0 To ListBox2.Items.Count - 1
                    s = ListBox2.Items.Item(i1)

                    file.WriteLine(s)

                Next i1
                file.Close()
            End If
            ProgressBar1.PerformStep()
        Next

    End Sub

End Class

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Help with reading file to buffer & sending


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway