Skip to content

Commit

Permalink
Fix VBA heuristic for Access Option Compare statement (github-linguis…
Browse files Browse the repository at this point in the history
…t#6742)

* Fix VBA heuristic for Access Option Compare statement

* Add VBA sample

* Add Binary option
  • Loading branch information
DecimalTurn authored Mar 10, 2024
1 parent aa11c2c commit 94e7b20
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ named_patterns:
- '^[ ]*#If Win64\b'
- '^[ ]*(?:Dim|Const) [0-9a-zA-Z_]*[ ]*As Long(?:Ptr|Long)\b'
# Top module declarations unique to VBA
- '^[ ]*Option (?:Private Module|Compare Database)\b'
- '^[ ]*Option (?:Private Module|Compare (?:Database|Text|Binary))\b'
# General VBA libraries and objects
- '(?: |\()(?:Access|Excel|Outlook|PowerPoint|Visio|Word|VBIDE)\.\w'
- '\b(?:(?:Active)?VBProjects?|VBComponents?|Application\.(?:VBE|ScreenUpdating))\b'
Expand Down
114 changes: 114 additions & 0 deletions samples/VBA/AccUnitLoaderConfigProcedures.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
Attribute VB_Name = "AccUnitLoaderConfigProcedures"
Option Explicit
Option Compare Text

Public Sub AddAccUnitTlbReference()
RemoveAccUnitTlbReference
CurrentVbProject.References.AddFromFile CurrentAccUnitConfiguration.AccUnitDllPath & "\AccessCodeLib.AccUnit.tlb"
End Sub

Public Sub RemoveAccUnitTlbReference()

Dim ref As Reference
Dim RefName As String

With CurrentVbProject
For Each ref In .References
On Error Resume Next
RefName = ref.Name
If Err.Number <> 0 Then
Err.Clear
RefName = vbNullString
End If
On Error GoTo 0
If RefName = "AccUnit" Then
.References.Remove ref
Exit Sub
End If
Next
End With

End Sub

Public Sub InsertFactoryModule()

Dim Configurator As AccUnit.Configurator

With New AccUnitLoaderFactory
Set Configurator = .Configurator
End With

Configurator.InsertAccUnitLoaderFactoryModule AccUnitTlbReferenceExists, True, CurrentVbProject, Application
Set Configurator = Nothing

On Error Resume Next
' Application.RunCommand acCmdCompileAndSaveAllModules

End Sub

Private Function AccUnitTlbReferenceExists() As Boolean

Dim ref As Reference
Dim RefName As String

For Each ref In CurrentVbProject.References
On Error Resume Next
RefName = ref.Name
If Err.Number <> 0 Then
Err.Clear
RefName = vbNullString
End If
On Error GoTo 0
If RefName = "AccUnit" Then
AccUnitTlbReferenceExists = True
Exit Function
End If
Next

End Function

Public Sub ImportTestClasses()

Dim Configurator As AccUnit.Configurator

With New AccUnitLoaderFactory
Set Configurator = .Configurator
End With

Configurator.InsertAccUnitLoaderFactoryModule AccUnitTlbReferenceExists, False, CurrentVbProject, Application
Configurator.ImportTestClasses
Set Configurator = Nothing

On Error Resume Next
' Application.RunCommand acCmdCompileAndSaveAllModules

End Sub

Public Sub ExportTestClasses()

Dim Configurator As AccUnit.Configurator

With New AccUnitLoaderFactory
Set Configurator = .Configurator
End With

Configurator.ExportTestClasses
Set Configurator = Nothing

End Sub

Public Sub RemoveTestEnvironment(ByVal RemoveTestModules As Boolean)

Dim Configurator As AccUnit.Configurator

With New AccUnitLoaderFactory
Set Configurator = .Configurator
End With

Configurator.RemoveTestEnvironment RemoveTestModules, , CurrentVbProject
Set Configurator = Nothing

On Error Resume Next
' Application.RunCommand acCmdCompileAndSaveAllModules

End Sub

0 comments on commit 94e7b20

Please sign in to comment.