prob using files and streams

want to use files and streams in windows appllications(vb 2008)

Page 1 of 1

8 Replies - 714 Views - Last Post: 08 November 2009 - 05:48 AM Rate Topic: -----

#1 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

prob using files and streams

Post icon  Posted 08 November 2009 - 03:13 AM

plz help me out in files and stream using in forms.
1st i design form
2nd when clicking add button all data in text boxes ill add into tht file
3rd after adding data then clicking on load button i want to load that data from the file then display in list boxes or text boxes in the form.
Imports System.IO



Public Class lbl

	Private Sub lbl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'File.Create("d:\test.txt")
		
	  
	End Sub

	Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbd1.Click
		Dim s As FileStream = New FileStream("d:\test.txt", FileMode.Append, FileAccess.Write)
		Dim a As StreamWriter = New StreamWriter(s)
		
		a.WriteLine(txtname.Text)
		a.WriteLine(txtfone.Text)
		a.WriteLine(txtcity.Text)
		a.WriteLine(txtaddress.Text)

		a.Close()
		s.Close()



	End Sub

	Private Sub load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbd2.Click
		Dim z As String
		Dim d As FileStream = New FileStream("d:\test.txt", FileMode.Open, FileAccess.Read)
		Dim c As StreamReader = New StreamReader(d)
	   
		While Not c.EndOfStream

			z = Console.ReadLine(txtname.Text)
			z = Console.ReadLine(txtfone.Text)
			z = Console.ReadLine(txtcity.Text)
			z = Console.ReadLine(txtaddress.Text)
		End While

		c.Close()
		d.Close()
		Dim s As FileStream = New FileStream("d:\test.txt", FileMode.Append, FileAccess.Write)
		Dim a As StreamWriter = New StreamWriter(s)
		z = Console.ReadLine(txtname.Text)
		a.WriteLine(txtname.Text)
		z = Console.ReadLine(txtfone.Text)
		a.WriteLine(txtfone.Text)
		z = Console.ReadLine(txtcity.Text)
		a.WriteLine(txtcity.Text)
		z = Console.ReadLine(txtaddress.Text)
		a.WriteLine(txtaddress.Text)
		a.Close()
		s.Close()

	End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: prob using files and streams

#2 nmgod  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 48
  • View blog
  • Posts: 233
  • Joined: 26-March 08

Re: prob using files and streams

Posted 08 November 2009 - 03:39 AM

what problems are you having? are there any errrors?
Was This Post Helpful? 0
  • +
  • -

#3 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: prob using files and streams

Posted 08 November 2009 - 04:02 AM

View Postnmgod, on 8 Nov, 2009 - 02:39 AM, said:

what problems are you having? are there any errrors?

no errors but my data is not displaying in the form textboxes .

This post has been edited by cindrellacool: 08 November 2009 - 04:03 AM

Was This Post Helpful? 0
  • +
  • -

#4 Donnie1581  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-November 09

Re: prob using files and streams

Posted 08 November 2009 - 04:08 AM

Post your whole code in here so we can see exactly whats going on. That will help us determine the problem.
Was This Post Helpful? 0
  • +
  • -

#5 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: prob using files and streams

Posted 08 November 2009 - 04:20 AM

View PostDonnie1581, on 8 Nov, 2009 - 03:08 AM, said:

Post your whole code in here so we can see exactly whats going on. That will help us determine the problem.

i posted my whole code before
Was This Post Helpful? 0
  • +
  • -

#6 nmgod  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 48
  • View blog
  • Posts: 233
  • Joined: 26-March 08

Re: prob using files and streams

Posted 08 November 2009 - 04:27 AM

Console.ReadLine(txtname.Text) doesnt read the line from textbox, it reads when you are making a console application.

you want to use c.ReadLine() instead

txtname.Text = c.ReadLine()
Was This Post Helpful? 0
  • +
  • -

#7 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: prob using files and streams

Posted 08 November 2009 - 04:58 AM

View Postnmgod, on 8 Nov, 2009 - 03:27 AM, said:

Console.ReadLine(txtname.Text) doesnt read the line from textbox, it reads when you are making a console application.

you want to use c.ReadLine() instead

txtname.Text = c.ReadLine()

CAN U TELL ME BY CODES I APPLY THT CODE BUT GIVING RUNTIME ERRORS
THX

This post has been edited by cindrellacool: 08 November 2009 - 05:01 AM

Was This Post Helpful? 0
  • +
  • -

#8 cindrellacool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 04-October 09

Re: prob using files and streams

Posted 08 November 2009 - 05:33 AM

Dim s As FileStream = New FileStream("d:\test.txt", FileMode.Append, FileAccess.Write)
		Dim a As StreamWriter = New StreamWriter(s)
	   
		 txtname.Text = c.ReadLine()
		a.WriteLine(txtname.Text)
		
		txtfone.Text = c.ReadLine()
		a.WriteLine(txtfone.Text)
		
		txtcity.Text = c.ReadLine()
		a.WriteLine(txtcity.Text)
		
		txtaddress.Text = c.ReadLine()
		a.WriteLine(txtaddress.Text)
		a.Close()
		s.Close()



these codes cannot write read files

This post has been edited by cindrellacool: 08 November 2009 - 05:35 AM

Was This Post Helpful? 0
  • +
  • -

#9 Donnie1581  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 05-November 09

Re: prob using files and streams

Posted 08 November 2009 - 05:48 AM

I misunderstood the question, so i Deleted what I had written.

I'll have to think for a minute to post a good solution.

This post has been edited by Donnie1581: 08 November 2009 - 05:54 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1