joyfullservice / msaccess-vcs-addin

Synchronize your Access Forms, Macros, Modules, Queries, Reports, and more with a version control system.
Other
203 stars 40 forks source link

problems with windows-1251 codepage in .bas (cyrrilic variables names) #246

Closed tst32 closed 3 years ago

tst32 commented 3 years ago

It seems that when i exported sources some weird happened with module.bas code image I open the code in notepad++ as well in vba debugger to show problem. This problem doesnot happened with forms or anything else but modules.bas

joyfullservice commented 3 years ago

@tst32 - Thank you for including the screenshot. It helps to see the additional details included there.

In the source code of the add-in, you can take a look at the modEncoding module, and especially the last function GetSystemEncoding(). This is where we attempt to map the local code page number to the corresponding string used when converting between the local encoding and UTF-8.

'---------------------------------------------------------------------------------------
' Procedure : GetSystemEncoding
' Author    : Adam Waller
' Date      : 3/8/2021
' Purpose   : Return the current encoding type used for non-UTF-8 text files.
'           : (Such as VBA code modules.)
'           : https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
'           : https://documentation.help/MS-Office-VB/ofhowConstants.htm
'           : * Note that using utf-8 as a default system encoding may not work
'           : correctly with some extended characters in VBA code modules. The VBA IDE
'           : does not support Unicode characters, and requires code pages to display
'           : extended/non-English characters. See Issues #60, #186, #180
'---------------------------------------------------------------------------------------
'
Public Function GetSystemEncoding() As String

    Static lngEncoding As Long

    ' Call API to determine active code page, caching return value.
    If lngEncoding = 0 Then lngEncoding = GetACP
    Select Case lngEncoding

        ' Language encoding mappings can be defined here
        Case msoEncodingISO88591Latin1:     GetSystemEncoding = "iso-8859-1"
        Case msoEncodingWestern:            GetSystemEncoding = "windows-1252"

        ' *In Windows 10, this is a checkbox in Region settings for
        ' "Beta: Use Unicode UTF-8 for worldwide language support"
        Case msoEncodingUTF8:               GetSystemEncoding = "utf-8"

        ' Any other language encoding not defined above
        Case Else
            ' Attempt to autodetect the language based on the content.
            ' (Note that this does not work as well on code as it does
            '  with normal written language. See issue #186)
            GetSystemEncoding = "_autodetect_all"
    End Select

End Function

I have not seen a source online that maps the constants with the string representations, but after looking at this more today, I was able to combine a couple of sources to come up with what I believe to be a comprehensive list.

joyfullservice commented 3 years ago

I have pushed an update to the dev branch which should resolve this issue, but please be aware that there are a couple other outstanding issues that need to be resolved before we can roll out version 3.4.x for general release. In the mean time, you can patch your version using the following steps:

  1. Open the add-in file
  2. Replace the GetSystemEncoding() function in modEncoding with the new version from e30ef71
  3. Save and close the add-in
  4. Open the (modified) add-in again, and click to install

This will install this update on your system. Let me know if this resolves the problem for you!

tst32 commented 3 years ago

Thanks! i followed your recomendations (edited modEncoding.bas), and it works like a charm! image

joyfullservice commented 3 years ago

That's awesome! Thanks for posting to confirm that the update solved the problem. This should be helpful for anyone else that is using a non-English codepage with VBA.