Cavan Posted June 20, 2003 Posted June 20, 2003 Hi folks. Newbie user here! Hope I'm in the right place - apologies if not. I'm having problems with the file handling syntax: I'm 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 Quote
Leaders Iceplug Posted June 20, 2003 Leaders Posted June 20, 2003 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") Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Cavan Posted June 20, 2003 Author Posted June 20, 2003 Thanks Iceplug, appreciate the response. I think I tried that earlier today, with the same result. I've 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, I've been programming with VB.net for precisely one day! I've got my application virtually finished on the Ipaq. I just can't do this usually simple thing - writing and reading back from a file. Thanks again Cavan Quote
*Experts* mutant Posted June 20, 2003 *Experts* Posted June 20, 2003 That code looks fine, can you show an example of your file and the characters you get when reading? Quote
Cavan Posted June 23, 2003 Author Posted June 23, 2003 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 haven't 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 Quote
*Experts* mutant Posted June 23, 2003 *Experts* Posted June 23, 2003 Try to change the encoding: Dim reader As New System.IO.StreamReader("file", System.Text.Encoding.UTF7) 'there is more encodings there Quote
Cavan Posted June 25, 2003 Author Posted June 25, 2003 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 didn't actually specify any encoding I would have thought it would have used default by default :) Thanks again. Much appreciated. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.