File Handling Syntax

Cavan

New member
Joined
Jun 20, 2003
Messages
4
Location
The Midlands, UK
Hi folks. Newbie user here! Hope Im in the right place - apologies if not.

Im having problems with the file handling syntax:

Im using:

File_Name = "\iPAQ File Store\locs.txt"
Dim sr As System.IO.StreamWriter = File.CreateText(File_Name)

sr.WriteLine(LB_LOCATION.Items(t))

to write data to a file. I can read the created file with no problem using Notepad.

However, using:

Dim sr As System.IO.StreamReader = New System.IO.StreamReader("\iPAQ File Store\locs.txt")

sline = sr.ReadLine
LB_LOCATION.Items.Add(sline)

to read the file in VB .net results in peculiar control characters being read in.

Any ideas what I am doing wrong? Is there another syntax I should use?

Many thanks

Cavan
 
You probably need to open the file with File.OpenText("\iPAQ File Store\locs.txt") to read the data in. :)
SR = File.OpenText("\iPAQ File Store\locs.txt")
 
Thanks Iceplug, appreciate the response. I think I tried that earlier today, with the same result. Ive tried three or four different ways of opening the file in VB.Net but just get gobbledegook back in. As I mentioned, the file seems fine - I can open it in notepad or word and the content is fine. Unfortunately, I really need to be able to read it back in to my application.

Incidentally, Ive been programming with VB.net for precisely one day! Ive got my application virtually finished on the Ipaq. I just cant do this usually simple thing - writing and reading back from a file.

Thanks again

Cavan
 
Hi Mutant - thanks for the replay.

Just as a simple test I output the word test to the file. As I said I can see it perfectly in things such as Notepad and Word. I havent had the the app in front of me since last week, but from memory, the result of the read back in the app is 6 characters in contrast to the 4 letters of test.

The first 2 characters are squares. Then something like !):;

Cheers

Cavan
 
Try to change the encoding:
Code:
Dim reader As New System.IO.StreamReader("file", System.Text.Encoding.UTF7)
there is more encodings there
 
Way to go Mutant! It works! Thanks VERY much.

I tried all the encoding options and got it to work with Default. Interesting. Since I didnt actually specify any encoding I would have thought it would have used default by default :)

Thanks again. Much appreciated.
 
Back
Top