Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Append to text file VB .Net
Closed Thread
Old 07-24-2006, 08:14 AM   #1 (permalink)
 
True Techie

Join Date: Sep 2002

Posts: 169

97lt2959

Default Append to text file VB .Net

Hi

I have another problem....

Im trying to write to a text file...

Well I say trying I have got it working... sort of!!

Code:
            
'**WRITES** Writes to the file
Dim StudentSW As New StreamWriter(StudentFileName, True)

StudentSW.WriteLine(TxtInputFirstName.Text, TxtInputLastName.Text, TxtInputDOB.Value, TxtInputHouseNo.Text, TxtInputAddressL1.Text)

' Closes the file
StudentSW.Close()
The problem I'm getting is its not writing all the fields to the text file. Only the first field, and I cant work out why...

I want them to appear all on the same line with a comma between each field..
__________________
Some System Specs:

Windows XP Service Pack 2
MXD 1600XB
CPU AMD Duron 1.6GHz
Memory 1.46GB DDR400 PC3200
HardDrive 40GB 7200rpm ATA133
Motherboard KM400 Chipset Skt A 333FSB
Graphics Card OnBoard 2D/3D Graphics
Sound Card OnBoard Sound
802.11b Wireless Network Card
Monitor GNR Flat Screen 15\"
Writer Combi - 52x32x52 CDRW + 16x DVD
Modem N/A - LAN 10/100 (Disabled)
Case Midi 300W ATX
Floppy 1.44MB 3.5\"
Keyboard A4TECH Wireless Keyboard
Mouse A4TECH Wireless Mouse
GNR Flat Screen LCD Monitor
97lt2959 is offline  
Old 07-24-2006, 07:19 PM   #2 (permalink)
 
Newb Techie

Join Date: Dec 2004

Posts: 45

Babbage

Default

The reason it is not writing as you expected, is because the WriteLine method you are trying to use does not exist.

http://msdn2.microsoft.com/en-us/lib...writeline.aspx

You might want to try something like the following:

StudentSW.Write(TxtInputFirstName.Text + ",")
StudentSW.Write(TxtInputLastName.Text + ",")
StudentSW.Write(TxtInputDOB.Value + ",")
StudentSW.Write(TxtInputHouseNo.Text + ",")
StudentSW.WriteLine(TxtInputAddressL1.Text)

Or, if you really wanted to put the whole thing in one statement, you would have to use one of writelines overload methods using a formatted string.

StudentSW.WriteLine("{1},{2},{3},{4},{5}", TxtInputFirstName.Text, TxtInputLastName.Text, TxtInputDOB.Value, TxtInputHouseNo.Text, TxtInputAddressL1.Text)

Check out here for how to format Strings:

http://www.builderau.com.au/architec...9177160,00.htm
Babbage is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On