View Full Version : OT: text file question
Greets to all and I hope that you will allow an off-topic, VB 2010 question?
I tackled a task with VB 2010 that deals with retrieving data from a game and then writing that data to a text file. Self-learning with VB was interesting, but the task does what I need. Now wanting to take the text files from VB and do some work in thinBasic I find that the output files from VB has some added characters at the beginning of the first line. These are CHR$(139), CHR$(175) and CHR$(168). I haven't a clue why they are there, but I'm going to do a quick and easy TB fix to read the file(s) and strip these out if found. Just another hurdle in my programming adventures!
Can anyone offer a thought as to why VB 2010 wants to start a file this way? Is it some type of encoding for the file? Not that I know anything about encoding of files...
Thanks,
Lance
Petr Schreiber
28-08-2012, 09:19
Hi Lance,
I think it might be related to fact VB.NET strings are unicode strings.
You might try forcing ASCII encoding when writing to file in the VB.NET app.
Petr
I see I never said Thank You for the response. So, Thanks Petr.
What I'm going to do as it involves an easy TB script is write a program to loop through my .TXT files and if the first line has the unwanted data at the front I will trim it and write a new file to disk. While I think VB is impressive in what it and other .Net tools can do, there is a sense of comfort using TB. Old men like comfortable things...
Lance
Petr Schreiber
15-09-2012, 07:15
Hello Lance,
I am happy you find ThinBASIC comfortable. I share your feeling - although I do coding in .NET too, coding in ThinBASIC feels a bit more pleasant experience.
I must admit I am still puzzled by the 3 characters on the beginning of the file, I didn't find it to be any of valid BOM signatures:
http://en.wikipedia.org/wiki/Byte_order_mark
Petr
Greets Petr,
This is what I had setup in VB Express 2010 for writing to the file;
Dim File1 As New StreamWriter(FileNameOut1, appendMode, System.Text.Encoding.UTF8 )
Dim File2 As New StreamWriter(FileNameOut2, appendMode, System.Text.Encoding.UTF8 )
Only by trying to load the TXT file into OpenOffice Calc did I discover the first line entries. Which I confirmed by opening the file with a HexEditor. Plain text editors displayed the text, without the BOM (?) entries, which I guess would be expected.
I've subsequently changed the line(s) above to read; ...Encoding.ASCII) and it outputs with no problem.
I've previously mentioned about working in the old BASIC PDS 7.1, circa 1990. So this new fangled encoding stuff takes some figuring out.
Lance
Edit: As I'm fixing dinner the thought pops into my head "Wonder if both computers using Windows XP64 could be the cause?". I'm slow to adopt new technology at times, as I just switched my primary computer to Windows 7 earlier this year. Windows 8? Maybe in 5-10 years?
Petr Schreiber
25-09-2012, 09:48
I searched the net a bit, and found out, that when you change these lines:
Dim File1 As New StreamWriter(FileNameOut1, appendMode, System.Text.Encoding.UTF8 )
Dim File2 As New StreamWriter(FileNameOut2, appendMode, System.Text.Encoding.UTF8 )
to these (note the encoding):
Dim File1 As New StreamWriter(FileNameOut1, appendMode, new UTF8Encoding(false) )
Dim File2 As New StreamWriter(FileNameOut2, appendMode, new UTF8Encoding(false) )
... it will no longer write the 3 strange characters on the beginning :) I tried it from C#, and it seems to work.
Petr