From c56706d33cfa08757f03899ca54b0e7e7dec4900 Mon Sep 17 00:00:00 2001 From: joyfullservice Date: Thu, 26 Jan 2023 09:01:46 -0600 Subject: [PATCH] Improve Unicode support for VBA code module import This change ensures that VBA code modules are imported using an 8-bit code page, even if the system encoding is using UTF-8 by default. We are currently hard coding Windows-1252 which supports English, French, German, and most other Western European languages, and is the most widely used codepage. This should allow people to use the Windows 10 option for Beta Unicode support. See #180, #246, #377 --- .../modules/clsDbModule.cls | 2 +- .../modules/modEncoding.bas | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Version Control.accda.src/modules/clsDbModule.cls b/Version Control.accda.src/modules/clsDbModule.cls index 8d747422..f46364a2 100644 --- a/Version Control.accda.src/modules/clsDbModule.cls +++ b/Version Control.accda.src/modules/clsDbModule.cls @@ -89,7 +89,7 @@ Private Sub IDbComponent_Import(strFile As String) ' Write to a new file using system encoding (converting from UTF-8) strTempFile = GetTempFile - WriteFile udtFile.strContent, strTempFile, GetSystemEncoding + WriteFile udtFile.strContent, strTempFile, GetSystemEncoding(False) ' Import the source code LoadVbeModuleFromFile strTempFile, strName diff --git a/Version Control.accda.src/modules/modEncoding.bas b/Version Control.accda.src/modules/modEncoding.bas index 1c5394e9..23501913 100644 --- a/Version Control.accda.src/modules/modEncoding.bas +++ b/Version Control.accda.src/modules/modEncoding.bas @@ -332,10 +332,10 @@ End Sub ' : * 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, #246 +' : extended/non-English characters. See Issues #60, #186, #180, #246, #377 '--------------------------------------------------------------------------------------- ' -Public Function GetSystemEncoding() As String +Public Function GetSystemEncoding(Optional blnAllowUtf8 As Boolean = True) As String Static lngEncoding As Long @@ -465,10 +465,18 @@ Public Function GetSystemEncoding() As String Case msoEncodingISCIIGujarati: GetSystemEncoding = "x-iscii-gu" Case msoEncodingISCIIPunjabi: GetSystemEncoding = "x-iscii-pa" Case msoEncodingUTF7: GetSystemEncoding = "utf-7" - Case msoEncodingUTF8: GetSystemEncoding = "utf-8" '* See note - ' *In Windows 10, this is a checkbox in Region settings for + ' In Windows 10, this is shown as a checkbox in Region settings for ' "Beta: Use Unicode UTF-8 for worldwide language support" + Case msoEncodingUTF8: + If blnAllowUtf8 Then + GetSystemEncoding = "utf-8" + Else + ' If UTF-8 is not allowed (such as for code modules), then fall back + ' to most commonly used codepage, supporting most Western Euorpean + ' languages, but not Cyrillic. https://www.wikiwand.com/en/Windows-1252 + GetSystemEncoding = "Windows-1252" + End If ' Any other language encoding not defined above (should be very rare) Case Else