473,654 Members | 3,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.t xt", True)
sw.WriteLine(tx t1.Text)

any suggestions on why it's not saving be great.
thanks for your help...
Nov 4 '08 #1
3 1660
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.t xt", True)
sw.WriteLine(tx t1.Text)
End Using
///

Cor

"karim" <ka***@discussi ons.microsoft.c omschreef in bericht
news:C2******** *************** ***********@mic rosoft.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.t xt", True)
sw.WriteLine(tx t1.Text)

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

Nov 4 '08 #2
"karim" <ka***@discussi ons.microsoft.c omschrieb:
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.t xt", True)
sw.WriteLine(tx t1.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...@discussi ons.microsoft.c omwrote:
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.t xt", True)
* * * * sw.WriteLine(tx t1.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.Fil eSystem.WriteAl lText("C:\SomeF ile.txt", _
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
1318
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 question, how do I add a new record to the database AFTER the user filled in the fields on the form. When the user presses a buttonNEW all controls (bound) need to be empty on the form so the user can fill in the fields. When the user presses the buttonSAVE...
9
15848
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 up a message on the screen that will tell the user that "Data has been changed, do you wish to Save the record before Closing this window?" I think I've just discovered this only works if the record that is being displayed/modified it not a...
4
3054
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 to save it. I have tried creating the object that I place into the DoDragDrop() by inheriting the COM interfaces IDropSource and IDataObject with no luck. If anyone can help I am very much open to suggestions. Thanks in advance!
3
2559
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: http://www.drpt.virginia.gov/temp1.gif All the fields on this form have validation controls on them so they can not submit the form unless all fields are completed and some fall within a specified numeric range. When the form first is loaded,...
4
428
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 to save the person's name in code behind protected void SavePersonInfo(Person p)
5
3923
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 form, I trigger the on acitvate event to run a macro. I can use the Dlookup function to update my fields, which is OK. However, I intitially tried to use the Repaint Object command to repaint the form. That did not work. Though I solved the...
8
2965
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, fields for address and telephone and a comment section i would like the form to fill in the address and telephone automatically once the name is chosen, (the only field the user can
6
2602
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 that is bound to a table and has no duplicates allowed. the problem is that there are 30 or so other controls here to be filled in and if the user selects a year and month that already has a record created, she/he won't know it until access tries to...
17
11866
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. There is 1 picture box on the form which I wish to save with the form so really a full screen shot of the form. Taking a screen shot and saving it won't do it either as the form is only a section of the screen say 640 X 480 and is centred on the...
17
7834
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 just me. For all users the database is hidden and only a menu screen is visable. Can I create a button on my menu screen that will export a table >
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8594
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.