473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

form won't save...?

Hello,
I have the simple code below to save text, but when I click the save btn
the form creates the file in the C drive, but it would not save what's in the
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
Nov 4 '08 #1
3 1645
Hi Karim,

The fact is that you are not closing the streamreader, that is implicitely
done by this code.
\\\
Using sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)
End Using
///

Cor

"karim" <ka***@discussions.microsoft.comschreef in bericht
news:C2**********************************@microsof t.com...
Hello,
I have the simple code below to save text, but when I click the save
btn
the form creates the file in the C drive, but it would not save what's in
the
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...

Nov 4 '08 #2
"karim" <ka***@discussions.microsoft.comschrieb:
I have the simple code below to save text, but when I click the save
btn
the form creates the file in the C drive, but it would not save what's in
the
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
The stream writer uses a buffer. You can either flush the buffer by calling
its 'Flush' method or by setting the 'AutoFlush' property. Closing the
stream writer will flush the buffer and persist the text to disk too (see
Cor's reply).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 4 '08 #3
On Nov 4, 8:33*am, karim <ka...@discussions.microsoft.comwrote:
Hello,
* * I have the simple code below to save text, but when I click the save btn
the form creates the file in the C drive, but it would not save what's inthe
text box.

Dim sw As New IO.StreamWriter("C:\SomeFile.txt", True)
* * * * sw.WriteLine(txt1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
Hi Karim,
As you can use StreamWriter with Using statement, you can shorten your
code by directly calling WriteAllText method as an alternative under
My namespace.

My.Computer.FileSystem.WriteAllText("C:\SomeFile.t xt", _
txt1.Text, True)

http://msdn.microsoft.com/en-us/libr...xs(VS.80).aspx

Also aware that UTF-8 is default in that method unless you specify
other encoding as 4th argument.

Hope this helps,

Onur Güzel
Nov 5 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maurice | last post by:
Hi In .NET I created a form with bound controls (Access Database). I used a dataset and followed examples to create a navigation using the Binding Context. So far everything goes well My...
9
by: Susan Bricker | last post by:
I am currently using the OnDirty event of a Form to detect whether any fields have been modified. I set a boolean variable. Then, if the Close button is clicked before the Save button, I can put...
4
by: Dave | last post by:
I need to add the ability to drag from a Windows Form and drop into a non dotNet application. For example, having a generated image in my app that I wish to drag out into explorer as a friendly way...
3
by: D. Shane Fowlkes | last post by:
Sorry for the length of this post. I have created a rather complex form which has a header/line item (parent and child records) structure. It's for an intranet. A screenshot can be seen here: ...
4
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object...
5
by: ortaias | last post by:
I have a form which calls up a second form for purposes of data entry. When closing the data entry form and returning to the main form, things don't work as expected. When I return to the main...
8
by: cwhite | last post by:
i want to create a form where the user can choose from a list of names in table A associated with this name is a telephone and address on the form there will be a drop list for the name,...
6
by: kaosyeti | last post by:
hey.... i have a duplicate record issue i could use some help with. on a form that has 2 unbound controls, txtboxyear and cboxmonth, together will automatically fill in an invisible txtboxdate...
17
dbanning
by: dbanning | last post by:
I am trying to save the contents of a form as a bitmap and am unsure how to do this. I can use the savepicture command to save the form as a bitmap but the contents is not intact as you would expect....
17
by: DeZZar | last post by:
Hi all, I need to regularly backup my database as an Excel file and have been using the File Export option. Problem is I need anyone using the database to be able to do this easily - nopt...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.