School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 353,769 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,865 people online right now.Registration is fast and FREE... Join Now!



Read test files line by line

52 Weeks of Code Challenge: WPF

Week #10 of the 52 Weeks of Code Challenge is WPF. If you're a .NET programmer, you should give it a shot. Click Here!
Page 1 of 1

Read test files line by line Rate Topic: -----

#1 Tonymon1  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 08


Dream Kudos: 0

Post icon  Posted 28 September 2008 - 08:50 AM

I want to open an existing file either when the form loads or with a command button. Then I want to click a button to view each next record. I know that streamreader only goes forward, but I need to master it before I start working with anything else. Simple text is fine right now. I'm using the VB2008 Express Edition. Thank you.


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Create streamreader and open text file
        Dim sr As IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("C:\testfile.txt")
        TextBox1.Text &= sr.ReadLine & vbCrLf
        TextBox1.Text &= sr.ReadLine & vbCrLf
        'Don't close the streamreader
        'sr.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim sr As IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("C:\testfile.txt")
        TextBox1.Text &= sr.ReadLine & vbCrLf
        TextBox1.Text &= sr.ReadLine & vbCrLf

    End Sub
End Class



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -


#2 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon

Reputation: 701
  • View blog
  • Posts: 16,787
  • Joined: 26-July 07


Dream Kudos: 12450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: Read test files line by line

Posted 28 September 2008 - 08:58 AM

Visual Basic 2008 (even the Express Edition) is VB.NET, so I'm moving this to the VB.NET forum :)
Was This Post Helpful? 0
  • +
  • -

#3 Tonymon1  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 08


Dream Kudos: 0

Re: Read test files line by line

Posted 29 September 2008 - 06:36 AM

It appears that this code resolves the problem. Thanks to all who looked.
Imports System.IO

Public Class Form1
	Private filename As String = "C:\test\testfile.txt"
	Private IntegerList As List(Of Integer)
	Private CurStream As StreamReader

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		CurStream = New StreamReader(filename)

	End Sub

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

		Dim CurRecord As String
		Dim strSplit() As String
		CurRecord = CurStream.ReadLine()
		If CurRecord Is Nothing Then
			MsgBox("No more records available")
		Else
			strSplit = CurRecord.Split(",")
			TextBox1.Text = strSplit(0)
			TextBox2.Text = strSplit(1)
			TextBox3.Text = strSplit(2)
			TextBox4.Text = strSplit(3)
		End If
	End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

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

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month