Jump to content
xisto Community
Sign in to follow this  
bob3695

Text File Operations VB.NET

Recommended Posts

When exploring data from vb.Net to excel.One column which is of string type is having the value 093949. In the excel it is showing as 93949.When the data is 034k89. It is printing correctly.How to get the data 093949 as it is.

 

Share this post


Link to post
Share on other sites
Extracting Formatted .txt file [fixed]Text File Operations VB.NET

The following is a cleaned up version of the above, it adds a <vbcr> to each line to preserve formatting, (useful for when reading .Htm and .Asp files).  It also outputs results to a RichTextBox.  The file name is pulled from a OpenFileDialog box and passed to a TextBox which in turn gets parsed by SteamReader.

------------------------------ Enjoy --------------------------------------

Imports SystemImports System.IO

Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk   Dim strm As System.IO.Stream   strm = OpenFileDialog1.OpenFile()   txtFile.Text = OpenFileDialog1.FileName.ToString()   Dim ioOutput As String = ""   If File.Exists(txtFile.Text) Then   Dim ioFile As New StreamReader(txtFile.Text)   Dim ioLine As String = ""   Dim ioLines As String = ""   While Not ioFile.EndOfStream   ioLine = ioFile.ReadLine   ioLines = ioLines & vbCrLf & ioLine   End While   ioOutput = ioLines   ioFile.Close()   End If   RichTextBox1.Text = ioOutput   End Sub

-reply by mgfranz

 

Share this post


Link to post
Share on other sites
How to add to the end of existing text file.Text File Operations VB.NET

Do you mean when you create the StreamWriter you want the Append option?  If so here's an example of how to set this up.

 Dim ioFile As New StreamWriter("MyFile.Txt",True)

 The "True" parameter after the name of the text file allows you to add to the end of the file rather than overwriting the info that is already in it.

-reply by bsee123

 

Share this post


Link to post
Share on other sites
I need to know how to read/write to all the files of a text file except the first line which i need to add the value of +1 toText File Operations VB.NETI am currently making a phonebook using visual basic (it has to use a text file to hold the contents of database) and I am currently stuggling on how to add one to the value of the first line. I am also struggling to write the entire contents of the text file to the database except for the first line despite using various strategies.Thank youBelow is the code that I have used and have completely stuffed up...Function saveinfo(ByRef fname, ByRef lname, ByRef mobile, ByRef homephone, ByRef address, ByRef birthday) Dim information As String information = fname & ":" & lname & ":" & mobile & ":" & homephone & ":" & address & ":" & birthday & ":" Dim database, firstline, line, blanc, file As String Dim savetofile As New System.IO.StreamReader(savefolder + "contacts (DON'T DELETE)") database = savetofile.ReadToEnd() firstline = savetofile.ReadLine() blanc = "" Dim number As String number = savetofile.ReadLine() number += 1 line = savetofile.ReadLine file = line While Not line = EOF(1) If line <> firstline Then file = file & vbCrLf & line End If End While savetofile.Close() Dim writetofile As New System.IO.StreamWriter(savefolder + "contacts (DON'T DELETE)") writetofile.WriteLine(file) writetofile.Write(information) writetofile.Close()

Share this post


Link to post
Share on other sites
Reading Textfiles in VB.NETText File Operations VB.NET

how to read a textfile in VB.NET ?? I have a problem regarding the reading of textfile to be save it into textbox 1, textbox2, etc.Example (textfile):Line1: 123 1234 123435Line2: ghj hjkl gbhjnOn line 1 the first value is 123, id like to save it on textbox1.? 1234(textbox2), etx..The same it to others.On line 2 the first value is ghj ,id like to save it on textbox3? etc...Hope to help me this issue.

-question by raKibOY

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.