Results 1 to 6 of 6

Thread: OT: text file question

  1. #1

    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$(16. 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

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    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

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    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?
    Last edited by LCSims; 25-09-2012 at 03:05.

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. save text file...
    By Lionheart008 in forum thinAir General
    Replies: 4
    Last Post: 13-05-2009, 22:50
  2. Help file text/syntax error
    By ISAWHIM in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 28-09-2008, 10:24
  3. control get text question
    By sandyrepope in forum UI (User Interface)
    Replies: 1
    Last Post: 21-06-2007, 22:04
  4. getting a line from text file
    By sandyrepope in forum UI (User Interface)
    Replies: 6
    Last Post: 04-03-2007, 05:36

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •