Skip to content

Commit

Permalink
Improve Unicode support for VBA code module import
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joyfullservice committed Jan 26, 2023
1 parent 7511e28 commit c56706d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Version Control.accda.src/modules/clsDbModule.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions Version Control.accda.src/modules/modEncoding.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c56706d

Please sign in to comment.