4 Replies - 1632 Views - Last Post: 19 November 2008 - 10:34 PM Rate Topic: -----

#1 ashura517  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-March 08

How to save data?

Posted 19 November 2008 - 03:38 AM

I have data received and is diplayed on the msgbox. How do i save it to a file?
Do i need to write to a text file?

Tried this but doesnt know how it works:
Dim FILE_NAME As String = "C:\test.txt"

		If System.IO.File.Exists(FILE_NAME) = True Then
			Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
			objWriter.Write(TextBox1.Text)
			objWriter.Close()
			MsgBox("Text written to file")
		Else
			MsgBox("File Does Not Exist")
		End If


Anyone here? Help! Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: How to save data?

#2 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: How to save data?

Posted 19 November 2008 - 06:25 AM

Hmmm If System.IO.File.Exists(FILE_NAME) = True Then, this is only going to write out to the file if it already exists. Is this the behaviour you want?
Was This Post Helpful? 0
  • +
  • -

#3 ashura517  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-March 08

Re: How to save data?

Posted 19 November 2008 - 06:57 AM

View Postmagicmonkey, on 19 Nov, 2008 - 05:25 AM, said:

Hmmm If System.IO.File.Exists(FILE_NAME) = True Then, this is only going to write out to the file if it already exists. Is this the behaviour you want?


nope..actually im not sure how it works. Saw that example somewhere. Im supposed to use StreamWriter to save data associated with my program. Does that make sense? It means that i have to create the text file first before saving the data?? And currently my data received is displayed by msgbox. How to save?
Was This Post Helpful? 0
  • +
  • -

#4 magicmonkey  Icon User is offline

  • D.I.C Regular

Reputation: 106
  • View blog
  • Posts: 484
  • Joined: 12-September 08

Re: How to save data?

Posted 19 November 2008 - 07:17 AM

Get rid of the IF statement...

            Dim FILE_NAME As String = "C:\test.txt"
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.WriteLine(TextBox1.Text)
            objWriter.Close()
            MsgBox("Text written to file")


Was This Post Helpful? 0
  • +
  • -

#5 ashura517  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-March 08

Re: How to save data?

Posted 19 November 2008 - 10:34 PM

View Postmagicmonkey, on 19 Nov, 2008 - 06:17 AM, said:

Get rid of the IF statement...

            Dim FILE_NAME As String = "C:\test.txt"
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.WriteLine(TextBox1.Text)
            objWriter.Close()
            MsgBox("Text written to file")



thanks!! it works!! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1