Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear All,

 

I am a newbie to VB.Net. I trying to get my (VB.Net) app to read from a text file and manipulate the read data and write the output to another text file. I can do it using VB6 and VBA, but not in VB.Net. I have a few questions I need sorted out.

 

1) what is the diff between fileopen and streamreader?

2) how do I use streamreader to read a line of text with a series of variables demilited by comma and then separated in different variables without using the split function?

3) how do I use streamwriter to do the reverse ie write a series of variables to a line of text and separated by commas?

4) I have declared a number of variables as various types eg long, integer, single, string etc. I would get an error message if the variables are of different type to the value being read and more importantly if a value is blank ie field is blank in the input file it would also return an error message. How do I get around this?

 

Your help and suggestions are greatly appreciated.

 

TIA

  • Administrators
Posted

1) FileOpen is the old non-.Net way of doing things and StreamReader is the correct way ;)

2)

 

Dim sr as new System.IO.StreamReader("C:\test.txt")
dim line as string
line = sr.ReadLine()
dim vals() as string = line.split(",")

 

3)

Dim swr as new System.IO.StreamWriter("C:\test.txt")
dim line as string
dim vals() as string = {"test","data","Only"}
line = line.join(vals,",")
sw.WriteLine(line)

 

4) bit more difficult but most data types have methods to support conversion i.e.

integer.Parse will parse a string into an integer

Long.ToString will convert to a string etc.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...