Skip to content

Commit

Permalink
Refactor code module export to shared function
Browse files Browse the repository at this point in the history
This logic will be shared when exporting code modules from forms and reports.
  • Loading branch information
joyfullservice committed Oct 24, 2023
1 parent 40cffbc commit 07e364e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
24 changes: 2 additions & 22 deletions Version Control.accda.src/modules/clsDbModule.cls
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,11 @@ Implements IDbComponent
'
Private Sub IDbComponent_Export(Optional strAlternatePath As String)

Dim strTempFile As String
Dim strContent As String
Dim strExt As String
Dim strAlternateFile As String

' Export to temp file and convert to UTF-8 encoding
strTempFile = GetTempFile
ExportVbComponent strTempFile
strContent = SanitizeVBA(ReadFile(strTempFile, GetSystemEncoding))
WriteFile strContent, Nz2(strAlternatePath, IDbComponent_SourceFile)
DeleteFile strTempFile
' Export as sanitized UTF-8 file
ExportCodeModule m_Module.Name, Nz2(strAlternatePath, IDbComponent_SourceFile)

' Remove any file with the same name but alternate extension
strExt = IIf(GetExtension = ".bas", ".cls", ".bas")
Expand Down Expand Up @@ -243,20 +237,6 @@ Private Sub IDbComponent_Merge(strFile As String)
End Sub


'---------------------------------------------------------------------------------------
' Procedure : ExportVbComponent
' Author : Adam Waller
' Date : 5/26/2021
' Purpose : Export the code module VB component
'---------------------------------------------------------------------------------------
'
Private Sub ExportVbComponent(strFile As String)
Perf.OperationStart "Export VBE Module"
CurrentVBProject.VBComponents(m_Module.Name).Export strFile
Perf.OperationEnd
End Sub


'---------------------------------------------------------------------------------------
' Procedure : IDbComponent_MoveSource
' Author : Adam Waller
Expand Down
30 changes: 30 additions & 0 deletions Version Control.accda.src/modules/modVCSUtility.bas
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,36 @@ Public Sub LoadComponentFromText(intType As AcObjectType, _
End Sub


'---------------------------------------------------------------------------------------
' Procedure : ExportVbComponent
' Author : Adam Waller
' Date : 5/26/2021
' Purpose : Export the code module VB component and convert to UTF-8
'---------------------------------------------------------------------------------------
'
Public Sub ExportCodeModule(strName As String, strFile As String)

Dim strTempFile As String
Dim strContent As String

Perf.OperationStart "Export VBE Module"

' Export to a temp file so we can convert to UTF-8 encoding
strTempFile = GetTempFile
CurrentVBProject.VBComponents(strName).Export strFile

' Sanitize the VBA code while reading the temp file
strContent = SanitizeVBA(ReadFile(strTempFile, GetSystemEncoding))

' Write the content as UTF-8 to the final destination
WriteFile strContent, strFile
DeleteFile strTempFile

Perf.OperationEnd

End Sub


'---------------------------------------------------------------------------------------
' Procedure : RemoveNonBuiltInReferences
' Author : Adam Waller
Expand Down

0 comments on commit 07e364e

Please sign in to comment.