Results 1 to 14 of 14

Thread: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    In my code editor, I usually use RC6.New_c.FSO.ReadTextContent(sFileName, , CP_UTF8) to open VB6 code files. That said, my code editor opens all VB6 code files in UTF-8.

    However, if the VB code file is encoded in ANSI, then when the VB code file is opened using the UTF-8, the Chinese characters in the VB code files will become garbled.

    I'd like to know, how to get the encoding format of the VB6 code files before opening them? Thanks!

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,799

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    If it's an ASCII file, then there's some confusion because ASCII is a perfect subset of UTF-8. If it's truly ANSI (with some of the characters using the 8th bit), but being interpreted as UTF-8, that can be problematic.

    But, are you sure you don't mean UTF-16?

    To my understanding, without a BOM marker, there's no bullet-proof way to differentiate ANSI from UTF-8. It's best if you just know which it is beforehand, and treat it as such when you read/write it.



    Just to say it, there are certain bit-sequences that wouldn't be allowed in a UTF-8 file. So, at certain times, we can detect that a file is not UTF-8. However, pretty much all bit-sequences are allowed in an ANSI file. So, an ANSI file that doesn't use the non-allowed UTF-8 bit sequences, may be erroneously interpreted as a UTF-8 file. That's the problem.
    Last edited by Elroy; May 17th, 2024 at 12:20 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Thank you, Elroy.

    I uploaded a test code, please check.
    Attached Files Attached Files

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,799

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by SearchingDataOnly View Post
    Thank you, Elroy.

    I uploaded a test code, please check.
    Sorry, but I don't do any RC#'ing. You may want to ask Schmidt.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by Elroy View Post
    Sorry, but I don't do any RC#'ing. You may want to ask Schmidt.
    You can use any method you are familiar with to read ModANSI.bas into a TextBox

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by The trick View Post
    https://github.com/thetrik/Vector06C.../CTextFile.cls - class with autodetection encoding.
    Hi The trick,

    I've just tested your CTextFile.cls and it seems to be able to automatically determine the format of the code file. But this class needs to use Vec06BAsConv.tlb. Could you provide a version that doesn't use Vec06BAsConv.tlb? Thanks.
    Last edited by SearchingDataOnly; May 18th, 2024 at 02:18 PM.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,799

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by SearchingDataOnly View Post
    You can use any method you are familiar with to read ModANSI.bas into a TextBox
    SDO, this is confusing. I'm not having any problems reading ASCII/ANSI/Unicode files. I'm aware I can read ModANSI.bas as a data file. Not sure I have any need to though.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by Elroy View Post
    SDO, this is confusing. I'm not having any problems reading ASCII/ANSI/Unicode files. I'm aware I can read ModANSI.bas as a data file. Not sure I have any need to though.
    Elroy, could you correctly display the Chinese characters in theModANSI.bas in the TextBox?

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,799

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Sure, VB6 is inherently ANSI:

    Name:  ANSI.jpg
Views: 503
Size:  13.3 KB
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,799

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Not sure that those are actually "Chinese" though, as I don't know Chinese. I suspect they're not.

    However, VB6's code window is never Unicode of any "brand". So, I'm quite unclear as to what you're trying to do.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by Elroy View Post
    Not sure that those are actually "Chinese" though, as I don't know Chinese. I suspect they're not.

    However, VB6's code window is never Unicode of any "brand". So, I'm quite unclear as to what you're trying to do.
    Here's the test screen on my computer:
    Attached Images Attached Images  

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    The trick's CTextFile.cls seems to be able to automatically determine the encoding format of the vb6 code files, but it needs to use Vec06BAsConv.tlb. I don't want to use an external tlb.

    Code:
    Private Sub CmdTheTrick_Click()
        Dim oFile As New cTextFile
        oFile.LoadTextFile App.Path & "\ModANSI.bas"
        Text1.Text = oFile.Content
    End Sub
    Last edited by SearchingDataOnly; May 18th, 2024 at 02:20 PM.

  13. #13
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,379

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Those Chinese characters will display correctly only if your Windows is in Chinese! For everyone else they will display as garbage as in Elroy's screenshot!

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,685

    Re: How to determine whether a VB6 code file is encoded in ANSI or UTF-8 ?

    Quote Originally Posted by VanGoghGaming View Post
    Those Chinese characters will display correctly only if your Windows is in Chinese! For everyone else they will display as garbage as in Elroy's screenshot!
    Yes. However, if these files are not read using the correct encoding format, Chinese characters will appear garbled even on Chinese computers.

Posting Permissions

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



Click Here to Expand Forum to Full Width