### Inno Setup Registry Entry Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process An example of a specific registry entry for Inno Setup, demonstrating the use of Root, Subkey, ValueType, ValueData, Flags, and Check parameters. ```text Root: "HKCU64"; Subkey: "Software\Classes\CLSID\{{40F71F29-D63F-4481-8A7D-E04A4B054501}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.PermissiveAssertClass"; Flags: uninsdeletekey; Check: IsWin64 and not InstallAllUsers ``` -------------------------------- ### Inno Setup Registry Writer Output Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process Illustrates multiple registry entries generated by the InnoSetupRegistryWriter for a single registry entry, handling 64-bit, 32-bit, and neutral hives with appropriate checks. ```text Root: "HKCU64"; Subkey: "Software\Classes\CLSID\{{69E194DA-43F0-3B33-B105-9B8188A6F040}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.AssertClass"; Flags: uninsdeletekey; Check: IsWin64 and not InstallAllUsers Root: "HKCU32"; Subkey: "Software\Classes\CLSID\{{69E194DA-43F0-3B33-B105-9B8188A6F040}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.AssertClass"; Flags: uninsdeletekey; Check: IsWin64 and not InstallAllUsers Root: "HKCU"; Subkey: "Software\Classes\CLSID\{{69E194DA-43F0-3B33-B105-9B8188A6F040}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.AssertClass"; Flags: uninsdeletekey; Check: not IsWin64 and not InstallAllUsers Root: "HKLM64"; Subkey: "Software\Classes\CLSID\{{69E194DA-43F0-3B33-B105-9B8188A6F040}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.AssertClass"; Flags: uninsdeletekey; Check: IsWin64 and InstallAllUsers Root: "HKLM32"; Subkey: "Software\Classes\CLSID\{{69E194DA-43F0-3B33-B105-9B8188A6F040}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.AssertClass"; Flags: uninsdeletekey; Check: IsWin64 and InstallAllUsers Root: "HKLM"; Subkey: "Software\Classes\CLSID\{{69E194DA-43F0-3B33-B105-9B8188A6F040}}"; ValueType: string; ValueName: ""; ValueData: "Rubberduck.UnitTesting.AssertClass"; Flags: uninsdeletekey; Check: not IsWin64 and InstallAllUsers ``` -------------------------------- ### COM Registration CLSID Entry Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Provides an example of a CLSID entry, linking 'Rubberduck.AssertClass' to its specific CLSID. ```plaintext ...\Rubberduck.AssertClass\CLSID @="{69E194DA-43F0-3B33-B105-9B8188A6F040}" ``` -------------------------------- ### Module Options Not Specified First Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/ModuleOptionsNotSpecifiedFirstInspection Demonstrates a module where options are not declared first. Module options control compilation and behavior, and their placement at the start improves code clarity. ```vb Option Compare Database Private foo As Integer Option Explicit Private bar As String Option Private Module Option Base 0 ``` -------------------------------- ### COM Registration Version Entry Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Provides a concrete example of a COM registration version entry, illustrating the expected values for a specific enumeration. ```plaintext ...\Record\{3E077C17-5678-3605-8449-FEABE42C9725}\2.1.6642.37961 "Class"="Rubberduck.API.VBA.DeclarationType" "Assembly"="Rubberduck, Version=2.1.6642.37961, Culture=neutral, PublicKeyToken=null" "RuntimeVersion"="v4.0.30319" "CodeBase"="C:\GitHub\Rubberduck\Rubberduck.Deployment\bin\Debug\Rubberduck.dll" ``` -------------------------------- ### Inno Setup Registry Entry Generic Form Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process This is the generic form of a registry entry in an Inno Setup script. Use this as a template for defining registry keys. ```text Root: ""; Subkey: ""; ValueType: ; ValueName: ""; ValueData: ""; Flags: Check: ``` -------------------------------- ### XML Example with CDATA Block Source: https://github.com/rubberduck-vba/rubberduck/wiki/Inspections-xml-doc Demonstrates the structure for a code example within an XML documentation tag, using CDATA to enclose the VBA code. This format is used when the example is expected to produce a result. ```xml ``` -------------------------------- ### Setup Child Mock with ComMock.SetupChildMock Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Use this method to configure a member call on the mock that returns an object reference. The returned object will also be mocked. This function also returns the configured mock, so multiple setup calls can be chained in the same instruction. ```vba Function SetupChildMock(Name As String, [Args]) As ComMock ``` -------------------------------- ### Setup Return Value with ComMock.SetupWithReturns Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Use this method to configure a member call on the mock so that it returns a specific value. ```vba Sub SetupWithReturns(Name As String, Value, [Args]) ``` -------------------------------- ### ComMock.SetupChildMock Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Specifies a setup on the mocked type for a call to an object member of the specified object type. Use this method to configure a member call on the mock that returns an object reference; the returned object will also be mocked. This function also returns the configured mock, so multiple setup calls can be chained in the same instruction. ```APIDOC ## ComMock.SetupChildMock ### Description Specifies a setup on the mocked type for a call to an object member of the specified object type. Use this method to configure a member call on the mock that returns an object reference; the returned object will also be mocked. This function also returns the configured mock, so multiple setup calls can be chained in the same instruction. ### Method Signature ```vb Function SetupChildMock(Name As String, [Args]) As ComMock ``` ``` -------------------------------- ### ModuleDescription and Description Annotations Example Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Applies '@ModuleDescription' for module-level documentation and '@Description' for function/sub-level documentation, akin to docstrings. ```vba '@ModuleDescription("Provides data-access utilities for the Orders table.") Option Explicit '@Description("Returns the next available order ID from the database.") Public Function GetNextOrderId() As Long GetNextOrderId = 42 ' implementation End Function ``` -------------------------------- ### VBA Method Signature for Example 5 Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This shows the resulting method signature for Example 5 after refactoring, indicating 'x' is passed by reference. ```vb Ex5: Sub NewMethod(byref x) ``` -------------------------------- ### VBA Method Signature for Example 2 Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This shows the resulting method signature for Example 2 after refactoring, indicating 'x' is passed by value. ```vb Ex2: Sub NewMethod(byval x) ``` -------------------------------- ### Pseudocode for Method Foo Source: https://github.com/rubberduck-vba/rubberduck/wiki/Code-Path-Analysis Illustrates a method with variable assignment, a conditional, and further assignment, serving as an example for path analysis. ```pseudocode method Foo(): var i = {someVal} if (condition) i = {val1} else doSomething(i) i = {val2} ``` -------------------------------- ### Setup Callback with ComMock.SetupWithCallback Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Specifies a callback to invoke when the method is called. The callback must be a public procedure defined in a standard module. ```vba Sub SetupWithCallback(Name As String, Callback As LongLong, [Args]) ``` -------------------------------- ### VBA Code Example 2 for Analysis Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This VBA code snippet is used as an example to demonstrate the data flow analysis for extract method refactoring. ```vb 'Example 2 Dim x as long Dim y as long Dim z as long x = 1 y = x 'selected z = 1 ``` -------------------------------- ### VBA Code Example 3 for Analysis Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This VBA code snippet is used as an example to demonstrate the data flow analysis for extract method refactoring. ```vb 'Example 3 Dim x as long Dim y as long Dim z as long x = 1 y = x 'selected z = x ``` -------------------------------- ### VBA Code Example 5 for Analysis Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This VBA code snippet is used as an example to demonstrate the data flow analysis for extract method refactoring, involving multiple selected lines. ```vb 'Example 5 Dim x as long Dim y as long Dim z as long z = 1 y = x 'selected x = 2 'selected z = x ``` -------------------------------- ### CLSID Registry Entry Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Example of a CLSID registry entry for a COM component implemented in .NET. This entry defines the unique identifier for the COM class. ```plaintext ...\CLSID\{69E194DA-43F0-3B33-B105-9B8188A6F040}] @="Rubberduck.UnitTesting.AssertClass" ``` -------------------------------- ### IgnoreOnceQuickFix Example Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Demonstrates how to use the 'Ignore Once' quick fix to suppress 'VariableNotUsed' inspections by inserting '@Ignore VariableNotUsed'. ```vba ' --- IgnoreOnceQuickFix --- ' Selecting "Ignore Once" on a VariableNotUsed result inserts '@Ignore VariableNotUsed': Public Sub Example() '@Ignore VariableNotUsed Dim unused As Long unused = 1 End Sub ``` -------------------------------- ### Execution Path Tree Structure Source: https://github.com/rubberduck-vba/rubberduck/wiki/Code-Path-Analysis Visual representation of the execution paths for the pseudocode example, showing nodes and branches. ```text [node] | {declaration(i)} | {assignment(i)} | [conditional] / \ [path1] [path2] | | {assignment(i)} {reference(i)} \ {assignment(i)} | [end] ``` -------------------------------- ### ComMock.ProgId Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Gets a string that represents a valid `CreateObject` target, or the name of a class in the user's VBA project. ```APIDOC ### ComMock.ProgId #### Description Gets a string that represents a valid `CreateObject` target, or the name of a class in the user's VBA project. #### Property Signature ```vb Property ProgId() As String ``` > **WARNING!** > The managed (.net Framework) proxy types will only be generated **ONCE** in the lifetime of the host process. While this works fine for compiled type libraries, avoid mocking (writing? see SOLID:OCP) user-code interfaces that are prone to require frequent modifications, because you'll need to shutdown and restart Excel and Rubberduck before you can run unit tests against the updated interface. ``` -------------------------------- ### IgnoreModule and Ignore Annotations Example Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Demonstrates suppressing inspections at the module level using '@IgnoreModule' and at specific lines using '@Ignore'. ```vba '@IgnoreModule HungarianNotation, ImplicitPublicMember Option Explicit Public Sub foo_bar() ' HungarianNotation suppressed at module level '@Ignore VariableNotUsed Dim tmp As Long ' suppressed at this line only tmp = 1 End Sub ``` -------------------------------- ### ComMock.SetupWithReturns Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Specifies a setup on the mocked type for a call to a value-returning method. Use this method to configure a member call on the mock so that it returns a specific value. ```APIDOC ## ComMock.SetupWithReturns ### Description Specifies a setup on the mocked type for a call to a value-returning method. Use this method to configure a member call on the mock so that it returns a specific value. ### Method Signature ```vb Sub SetupWithReturns(Name As String, Value, [Args]) ``` ``` -------------------------------- ### Initialize MockProvider and Mock Excel.Application Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Demonstrates initializing the MockProvider and creating a mock for Excel.Application. Use this to set up mocks for COM objects and configure their behavior for testing. ```vba Option Explicit 'Private Assert As Rubberduck.AssertClass 'Private Fakes As Rubberduck.FakesProvider Private Mocks As Rubberduck.MockProvider '@ModuleInitialize Private Sub ModuleInitialize() 'this method runs once per module. 'Set Assert = New Rubberduck.AssertClass 'Set Fakes = New Rubberduck.FakesProvider Set Mocks = New Rubberduck.MockProvider End Sub '@TestMethod("Uncategorized") Public Sub TestMethod1() 'arrange Dim Mock As Rubberduck.ComMock Set Mock = Mocks.Mock("Excel.Application") 'here we create a new mock using the Excel.Application progid 'then we configure our mock as per our needs... Mock.SetupWithReturns "Name", "Mocked-Excel" Mock.SetupWithCallback "CalculateFull", AddressOf OnAppCalculate Dim Mocked As Excel.Application Set Mocked = Mock.Object 'ComMock.Object represents the mocked object and always implements the COM interface it's mocking 'act 'just making sure the mock works :) Debug.Print Mocked.Name Mocked.CalculateFull 'it would normally look more like this: we inject the mocked dependency into the object we want to test in isolation. 'With SomeMacro.Create(Mocked) ' .Execute 'End With 'assert 'use the ComMock.Verify method to fail the test if a method that was setup was not invoked as per the test's specifications: Mock.Verify "CalculateFull", Mocks.Times.AtLeastOnce End Sub Public Sub OnAppCalculate() 'we can use AddressOf to implement callbacks that the mock will invoke instead of the concrete method: Debug.Print "A full recalc was made by the mocked Excel.Application instance." End Sub ``` -------------------------------- ### ComMock.Setup Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Configures a setup on the mocked type for a call to a method that does not return a value (Sub or Property Let/Set). Use `MockProvider.It` for argument specifications. ```APIDOC ### ComMock.Setup #### Description Specifies a setup on the mocked type for a call to a method that does not return a value. Use this method to configure a member call on the mock, that does not return a value (so, a `Sub` or `Property Let`/`Set` procedure). > **NOTE** > Use `MockProvider.It` to specify the `Args` of all `Setup` and `Verify` methods. #### Method Signature ```vb Sub Setup(Name As String, [Args]) ``` ``` -------------------------------- ### ComMock.SetupWithCallback Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Specifies a callback to invoke when the method is called. The callback must be a public procedure defined in a standard module. ```APIDOC ## ComMock.SetupWithCallback ### Description Specifies a callback (use the AddressOf operator) to invoke when the method is called that receives the original invocation. The callback must be a public procedure defined in a standard module. ### Method Signature ```vb Sub SetupWithCallback(Name As String, Callback As LongLong, [Args]) ``` ``` -------------------------------- ### VBA Method Signature for Example 4 Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This shows the resulting method signature for Example 4 after refactoring, indicating 'x' is passed by reference. ```vb Ex4: Sub NewMethod(byref x) ``` -------------------------------- ### VBA Method Signature for Example 3 Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This shows the resulting method signature for Example 3 after refactoring, indicating 'x' is passed by value. ```vb Ex3: Sub NewMethod(byval x) ``` -------------------------------- ### Setup Mocked Method (Sub/Property) Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Use this method to configure a call to a mocked type's member that does not return a value (i.e., a Sub or Property Let/Set procedure). Use MockProvider.It to specify the arguments. ```VBA Sub Setup(Name As String, [Args]) ``` -------------------------------- ### TypeLib GUID Registration Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Defines the registry key for a Type Library, identified by its unique GUID. This corresponds to the assembly version in .NET projects. ```registry ...\TypeLib\{E07C841C-14B4-4890-83E9-8C80B06DD59D} ``` -------------------------------- ### Registry Deletion Script Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process This is an example of a registry script generated by the LocalDebugRegistryWriter to delete previously added registry keys. It is formatted for Windows Registry Editor. ```reg Windows Registry Editor Version 5.00 [-HKEY_CURRENT_USER\Software\Classes\CLSID\{40F71F29-D63F-4481-8A7D-E04A4B054501}] [-HKEY_CURRENT_USER\Software\Classes\CLSID\{40F71F29-D63F-4481-8A7D-E04A4B054501}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}] ... ``` -------------------------------- ### Implement Pre-Build Event Task Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process Define a Target for the pre-build event to execute the custom RubberduckPreBuildTask. Pass necessary parameters like WorkingDir and OutputDir. ```xml ``` -------------------------------- ### VBA Method Signature for Example 6 Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This shows the resulting method signature for Example 6 after refactoring, indicating 'x' and 'y' are passed by reference, and 'y' is also declared externally. ```vb Ex6: Sub NewMethod(byref x, byref y) - extract dim of y ``` -------------------------------- ### Get Pivot Column or Row Field Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Preprocessor/Reference_Module_2_Processed.txt Retrieves a PivotField that is specifically a column or row field. It first attempts to get the field by its name or index and then checks its orientation. ```VBA Public Function GetPivotCRField(PivotFields As Excel.PivotFields, FieldNV As tyNameValue) As Excel.PivotField Const ThisProcedure As String = ThisModule & "|GetPivotCRField|Function" Dim lcPivotField As Excel.PivotField Dim lvVarType As VBA.VbVarType Set lcPivotField = GetPivotFieldOrNothing(PivotFields:=PivotFields, Index:=FieldNV.Value) If lcPivotField Is Nothing Then RaisePivotFieldDoesNotExist NameValue:=FieldNV Else With lcPivotField If .Orientation = XlPivotFieldOrientation.xlColumnField _ Or .Orientation = XlPivotFieldOrientation.xlRowField Then Set GetPivotCRField = lcPcpivotField Else RaisePivotFieldNoColumnNoRow NameValue:=FieldNV End If End With End If Set lcPivotField = Nothing End Function ``` -------------------------------- ### Version-specific InProcServer32 Registry Structure Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Demonstrates the generic and example structure for version-specific InProcServer32 keys, allowing for customized behavior based on component version. ```plaintext ...\CLSID\{}\InprocServer32\ ``` ```plaintext ...\CLSID\{69E194DA-43F0-3B33-B105-9B8188A6F040}\InprocServer32\2.1.6642.37961 "Class"="Rubberduck.UnitTesting.AssertClass" "Assembly"="Rubberduck, Version=2.1.6642.37961, Culture=neutral, PublicKeyToken=null" "RuntimeVersion"="v4.0.30319" "CodeBase"="C:\GitHub\Rubberduck\Rubberduck.Deployment\bin\Debug\Rubberduck.dll" ``` -------------------------------- ### Example Commit Graph for Green Releases Source: https://github.com/rubberduck-vba/rubberduck/wiki/Releasing-Rubberduck Illustrates a simplified commit graph structure resulting from the green release process, emphasizing fast-forward merges and their impact on conflict resolution and ancestry determination. ```git o [next, Prerelease-v...] Merge Pull Request <> o [master, Prerelease-v..., v...] Merge Pull Request into master |\ | o [Prerelease-v...] Merge Pull Request <> | o [Prerelease-v...] Merge Pull Request <> |/ o [v..., Prerelease-v...] Merge Pull Request into master |\ | o ... . . ``` -------------------------------- ### VBA Code Example 4 for Analysis Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This VBA code snippet is used as an example to demonstrate the data flow analysis for extract method refactoring, involving multiple selected lines. ```vb 'Example 4 Dim x as long Dim y as long Dim z as long x = 1 z = 1 y = x 'selected x = 2 'selected z = x ``` -------------------------------- ### Record Enumeration GUID Registration Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Assigns a unique GUID to an enumeration defined within a DLL. This allows consumers like Visual Basic to map enumeration values to their literal names during compilation. ```registry $\...\\Record\\{3E077C17-5678-3605-8449-FEABE42C9725} ``` -------------------------------- ### COM Registration ProgId Entry Example Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Illustrates a specific ProgId entry for Rubberduck, mapping 'Rubberduck.AssertClass' to its fully qualified class name. ```plaintext ...\Rubberduck.AssertClass @="Rubberduck.UnitTesting.AssertClass" ``` -------------------------------- ### VBA Code Example 6 for Analysis Source: https://github.com/rubberduck-vba/rubberduck/wiki/Extract-Method-Refactoring-:-Workings---Determining-what-params-to-move This VBA code snippet is used as an example to demonstrate the data flow analysis for extract method refactoring, involving multiple selected lines and a declaration within the selection. ```vb 'Example 6 Dim x as long Dim z as long z = 1 Dim y as long 'selected y = x 'selected x = 2 'selected z = y ``` -------------------------------- ### MockProvider.It Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Provides flexible ways to specify argument matching for mocked method invocations using the `SetupArgumentCreator` API. ```APIDOC ## MockProvider.It ### Description This get-only property exposes the `SetupArgumentCreator` API, which allows for many flexible ways to specify exactly how a mocked method is supposed to be invoked by the code under test. ### Available Functions - `Function Is(Value)` sets up an argument that must be the specified value - `Function IsAny()` sets up a placeholder argument that does not need to have any particular value - `Function IsIn(Values() As variant)` sets up an argument that must be one of the specified values (use `VBA.Array()` to specify them inline) - `Function IsInRange(Start, End, Range As SetupArgumentRange)` sets up an argument that must be within a range of values - `Function IsNotIn(Values() As Variant)` sets up an argument that must _not_ be any of the specified values - `Function IsNotNull()` sets up an argument that must be any non-null (`Nothing`) object reference All these functions create and return a `SetupArgumentDefinition` object. #### MockProvider.SetupArgumentDefinition Class This class encapsulates the metadata for an argument, including its type and values. The type is a `SetupArgumentType` enum constant that describes how the argument should be validated: - `SetupArgumentType_Is = 0` - `SetupArgumentType_IsAny = 1` - `SetupArgumentType_IsIn = 2` - `SetupArgumentType_IsInRange = 3` - `SetupArgumentType_IsNotIn = 4` - `SetupArgumentType_IsNotNull = 5` The `Property Values() As Variant()` read-only array holds the arguments needed to perform the operations. #### MockProvider.SetupArgumentDefinitions Class This class represents an enumerable collection (should work with `For Each`) of `SetupArgumentDefinition` objects, exposing a `Count` and an `Item(Index As Long)` default property. ``` -------------------------------- ### Minimal rubberduck.config for Troubleshooting Source: https://github.com/rubberduck-vba/rubberduck/wiki/Troubleshooting-and-reporting-an-issue Use this minimal XML configuration to create a `rubberduck.config` file manually. This is useful when the file is missing and Rubberduck fails to load, ensuring basic functionality. ```xml true true true false false 10 false 6 ``` -------------------------------- ### Get Worksheet Pivot Table Range Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_11.txt Activates a specified worksheet, gets its first pivot table, and returns the `TableRange1` of that pivot table. Requires the worksheet to exist and contain at least one pivot table. ```VBA Private Function WorksheetPTR(WorksheetName As String) As Excel.Worksheet Const ThisProcedure As String = ThisModule & "|WorksheetPTR|Function" Dim lcWorksheet As Excel.Worksheet Dim lcPivotTable As Excel.PivotTable Set lcWorksheet = ActiveWorkbook.Worksheets(Index:=WorksheetName) With lcWorksheet .Activate Set lcPivotTable = .PivotTables(1) End With Set WorksheetPTR = lcPivotTable.TableRange1 Set lcPivotTable = Nothing Set lcWorksheet = Nothing End Function ``` -------------------------------- ### Get Pivot Column or Row Field Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Preprocessor/Reference_Module_2.txt Retrieves a PivotField that is specifically a column or row field. It first attempts to get the field by its value and then checks its orientation. Raises an error if the field does not exist or is not a column or row field. ```VBA Public Function GetPivotCRField(PivotFields As Excel.PivotFields, FieldNV As tyNameValue) As Excel.PivotField Const ThisProcedure As String = ThisModule & "|GetPivotCRField|Function" Dim lcPivotField As Excel.PivotField Dim lvVarType As VBA.VbVarType Set lcPivotField = GetPivotFieldOrNothing(PivotFields:=PivotFields, Index:=FieldNV.Value) If lcPivotField Is Nothing Then RaisePivotFieldDoesNotExist NameValue:=FieldNV Else With lcPivotField If .Orientation = XlPivotFieldOrientation.xlColumnField _ Or .Orientation = XlPivotFieldOrientation.xlRowField Then Set GetPivotCRField = lcPivotField Else RaisePivotFieldNoColumnNoRow NameValue:=FieldNV End If End With End If Set lcPivotField = Nothing End Function ``` -------------------------------- ### Implement Custom Quick Fix in C# Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Extends `QuickFixBase` to add a custom quick fix. Declare supported inspections in the constructor and implement the `Fix` method for the desired action. This example adds an '@Description("TODO")' annotation. ```csharp internal sealed class AddDescriptionAnnotationQuickFix : QuickFixBase { private readonly IAnnotationUpdater _annotationUpdater; public AddDescriptionAnnotationQuickFix(IAnnotationUpdater annotationUpdater) : base(typeof(MissingDescriptionInspection)) { _annotationUpdater = annotationUpdater; } public override void Fix(IInspectionResult result, IRewriteSession rewriteSession) { _annotationUpdater.AddAnnotation( rewriteSession, new QualifiedContext(result.QualifiedSelection.QualifiedName, result.Context), new DescriptionAnnotation(), new List { "TODO" }); } public override string Description(IInspectionResult result) => "Add '@Description' annotation"; public override bool CanFixMultiple => true; public override bool CanFixInProcedure => false; public override bool CanFixInModule => true; public override bool CanFixInProject => true; public override bool CanFixAll => true; } ``` -------------------------------- ### Create InnoSetup Registry File Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process This method creates a .reg.iss file for InnoSetup using the `InnoSetupRegistryWriter`. It writes the content with UTF8 BOM encoding for Unicode support. ```csharp private void CreateInnoSetupRegistryFile(IOrderedEnumerable entries, DllFileParameters parameters) { var writer = new InnoSetupRegistryWriter(); var content = writer.Write(entries, parameters.DllFile, parameters.Tlb32File, parameters.Tlb64File); var regFile = Path.Combine(IncludeDir, parameters.DllFile.Replace(".dll", ".reg.iss")); // To use unicode with InnoSetup, encoding must be UTF8 BOM File.WriteAllText(regFile, content, new UTF8Encoding(true)); } ``` -------------------------------- ### Implement Post-Build Event Task Source: https://github.com/rubberduck-vba/rubberduck/wiki/Build-process Define a Target for the post-build event to execute the custom RubberduckPostBuildTask. This task requires several parameters for configuration, including tool directories and source/target paths. ```xml ``` -------------------------------- ### GetPivotTableRowLabelRange Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_11.txt Gets the range representing the row labels of a PivotTable. ```APIDOC ## GetPivotTableRowLabelRange ### Description Returns the Excel Range object that corresponds to the row labels (headers) of a given PivotTable. ### Method ```vba Public Function GetPivotTableRowLabelRange(PivotTable As Excel.PivotTable) As Excel.Range ``` ### Parameters * **PivotTable** (Excel.PivotTable) - The PivotTable object for which to get the row label range. ### Returns * **Excel.Range** - The Range object representing the row labels. ``` -------------------------------- ### GetPivotTableColumnLabelRange Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_11.txt Gets the range representing the column labels of a PivotTable. ```APIDOC ## GetPivotTableColumnLabelRange ### Description Returns the Excel Range object that corresponds to the column labels (headers) of a given PivotTable. ### Method ```vba Public Function GetPivotTableColumnLabelRange(PivotTable As Excel.PivotTable) As Excel.Range ``` ### Parameters * **PivotTable** (Excel.PivotTable) - The PivotTable object for which to get the column label range. ### Returns * **Excel.Range** - The Range object representing the column labels. ``` -------------------------------- ### Generate PIA using tlbimp Source: https://github.com/rubberduck-vba/rubberduck/wiki/Adding-a-new-Host-Application-to-Rubberduck Use the `tlbimp` command-line tool to generate a PIA from a Type Library. This is a necessary step for enabling unit testing with custom host applications. ```bash tlbimp HostAppCOM.tlb /out:HostApp.Interop.dll ``` -------------------------------- ### Register New Host Application Source: https://github.com/rubberduck-vba/rubberduck/wiki/Adding-a-new-Host-Application-to-Rubberduck Add a new case to the `HostApplicationExtensions` class to register your custom host application. This allows Rubberduck to identify and instantiate your application. ```csharp case "YourApplication": return new YourApplicationApp(); ``` -------------------------------- ### Test Annotations Example Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Illustrates the use of various test annotations like '@TestModule', '@TestMethod', '@TestInitialize', '@TestCleanup', '@ModuleInitialize', and '@ModuleCleanup' for structuring unit tests. ```vba '@TestModule '@Folder("Tests.Unit") Option Explicit Private Assert As New Rubberduck.AssertClass Private Fakes As Rubberduck.FakesProvider '@ModuleInitialize Public Sub ModuleInitialize() ' Runs once before any test in this module End Sub '@ModuleCleanup Public Sub ModuleCleanup() ' Runs once after all tests in this module End Sub '@TestInitialize Public Sub TestInitialize() Set Fakes = New Rubberduck.FakesProvider End Sub '@TestCleanup Public Sub TestCleanup() Set Fakes = Nothing End Sub '@TestMethod Public Sub MyTest() On Error GoTo TestFail Assert.Succeed TestExit: Exit Sub TestFail: Assert.Fail "Error " & Err.Number & ": " & Err.Description End Sub ``` -------------------------------- ### RemoveUnusedDeclarationQuickFix Example Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Demonstrates the 'RemoveUnusedDeclarationQuickFix' which cleans up code by removing unused variable declarations. ```vba ' --- RemoveUnusedDeclarationQuickFix --- ' Before (VariableNotUsed): Public Sub Calc() Dim temp As Long temp = 99 Debug.Print 99 End Sub ' After: Public Sub Calc() Debug.Print 99 End Sub ``` -------------------------------- ### Get PivotTable from Range Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_17.txt Retrieves the PivotTable associated with a given Excel range. Errors are ignored. ```VBA Public Function GetPivotTableOrNothingFromRange(Range As Excel.Range) As Excel.PivotTable Const ThisProcedure As String = ThisModule & "|GetPivotTableOrNothingFromRange|Function" On Error Resume Next Set GetPivotTableOrNothingFromRange = Range.PivotTable End Function ``` -------------------------------- ### Flexible Argument Matching Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework The It property exposes the SetupArgumentCreator API for flexible specification of mocked method arguments. Use these functions to define precise matching criteria for arguments. ```VBA Function Is(Value) ``` ```VBA Function IsAny() ``` ```VBA Function IsIn(Values() As variant) ``` ```VBA Function IsInRange(Start, End, Range As SetupArgumentRange) ``` ```VBA Function IsNotIn(Values() As Variant) ``` ```VBA Function IsNotNull() ``` -------------------------------- ### InProcServer32 Registry Structure Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Illustrates the generic and example registry entries for InProcServer32, which defines how a COM component is activated and located, including .NET specific attributes. ```plaintext ...\CLSID\{}\InprocServer32 @="" "ThreadingModel"="" "Class"="" "Assembly"=", Version=, Culture=, PublicKeyToken=" "RuntimeVersion"="" "CodeBase"="" ``` ```plaintext ...\CLSID\{69E194DA-43F0-3B33-B105-9B8188A6F040}\InprocServer32 @="mscoree.dll" "ThreadingModel"="Both" "Class"="Rubberduck.UnitTesting.AssertClass" "Assembly"="Rubberduck, Version=2.1.6642.37961, Culture=neutral, PublicKeyToken=null" "RuntimeVersion"="v4.0.30319" "CodeBase"="C:\GitHub\Rubberduck\Rubberduck.Deployment\bin\Debug\Rubberduck.dll" ``` -------------------------------- ### Get PivotTables from Worksheet Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_17.txt Retrieves all PivotTables associated with a given Excel worksheet. Errors are ignored. ```VBA Public Function GetPivotTablesOrNothing(Worksheet As Excel.Worksheet) As Excel.PivotTables Const ThisProcedure As String = ThisModule & "|GetPivotTablesOrNothing|Function" On Error Resume Next Set GetPivotTablesOrNothing = Worksheet.PivotTables End Function ``` -------------------------------- ### Type Library Help Directory Registration Source: https://github.com/rubberduck-vba/rubberduck/wiki/COM-Registration Specifies the directory containing help files for a type library. This is used to locate help files if they are not specified with an absolute path. ```registry $\...\TypeLib\{E07C841C-14B4-4890-83E9-8C80B06DD59D}\\2.1\\HELPDIR @="C:\\GitHub\\Rubberduck.Deployment\\bin\\Debug\\" ``` -------------------------------- ### SpecifyExplicitByRefModifierQuickFix Example Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Shows the transformation from an implicit ByRef parameter modifier to an explicit one using the 'SpecifyExplicitByRefModifierQuickFix'. ```vba ' --- SpecifyExplicitByRefModifierQuickFix --- ' Before (ImplicitByRefModifier flagged): Public Sub Proc(x As Long) End Sub ' After quick fix: Public Sub Proc(ByRef x As Long) End Sub ``` -------------------------------- ### ComMock.Object Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Gets a reference to the mocked COM object. This reference can be safely cast to the mocked interface type. ```APIDOC ## Rubberduck.ComMock ### ComMock.Object #### Description Gets a reference to the mocked COM object; this reference is exposed as `Object`, but can always safely be cast to the mocked interface type. #### Property Signature ```vb Property Object() As Object ``` ``` -------------------------------- ### VBA Unit Test Module Setup Source: https://context7.com/rubberduck-vba/rubberduck/llms.txt Demonstrates the structure of a test module using Rubberduck's unit testing framework. Requires '@TestModule' annotation and declaration of AssertClass and FakesProvider. Test methods are marked with '@TestMethod'. ```vba '@TestModule '@Folder("Tests") Option Explicit Private Assert As New Rubberduck.AssertClass Private Fakes As Rubberduck.FakesProvider '@TestInitialize Public Sub TestInitialize() ' runs before every test method Set Fakes = New Rubberduck.FakesProvider End Sub '@TestCleanup Public Sub TestCleanup() ' runs after every test method Set Fakes = Nothing End Sub '@TestMethod Public Sub AcceptsNumericKeys() On Error GoTo TestFail 'Arrange Dim sut As New NumKeyValidator Dim value As String value = vbNullString 'Act & Assert Dim i As Integer Dim result As Boolean For i = 0 To 9 result = sut.IsValidKey(Asc(CStr(i)), value) Assert.IsTrue result, "Digit " & i & " was rejected" Next i TestExit: Exit Sub TestFail: Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description End Sub '@TestMethod Public Sub RejectsDotWhenValueAlreadyHasDot() On Error GoTo TestFail 'Arrange Dim sut As New NumKeyValidator Dim actual As Boolean 'Act actual = sut.IsValidKey(Asc("."), "3.14") 'Assert Assert.IsFalse actual, "Dot should be rejected when value already contains a dot" TestExit: Exit Sub TestFail: Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description End Sub ``` -------------------------------- ### Get PivotTable by Index Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_17.txt Retrieves a PivotTable from a collection by its index. Handles potential errors if the index is invalid. ```VBA Public Function GetPivotTableOrNothing(PivotTables As Excel.PivotTables, Index As Variant) As Excel.PivotTable Const ThisProcedure As String = ThisModule & "|GetPivotTableOrNothing|Function" On Error Resume Next Set GetPivotTableOrNothing = PivotTables.Item(Index:=Index) End Function ``` -------------------------------- ### MockProvider.Mock Source: https://github.com/rubberduck-vba/rubberduck/wiki/VBA-Moq-Mocking-Framework Creates and returns a new mock for a specified interface or progID (or GUID) string. 'ProgId' is the class to mock, and 'Project' is an optional parameter to disambiguate class names across projects. ```APIDOC ## MockProvider.Mock ### Description This method creates and returns a new mock for a specified interface or progID (or GUID) string. - **ProgId** is a `String` parameter that can be any valid input for `CreateObject`; for user code it would be the name of the class to mock. - **Project** is an optional `String` parameter; for user code, it serves to disambiguate class names that could be the same but in separate projects. ### Function Signature ```vb Function Mock(ProgId As String, [Project As String]) As ComMock ``` ``` -------------------------------- ### Get Excel PivotItem Position Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_15.txt Retrieves the position of a PivotItem within its collection. Assumes the PivotItem is valid. ```VBA Public Function GetPivotItemPosition(PivotItem As Excel.PivotItem) As Long Const ThisProcedure As String = ThisModule & "|GetPivotItemOrNothing|Function" On Error Resume Next GetPivotItemPosition = PivotItem.Position End Function ``` -------------------------------- ### Register Existing Instance as Singleton Source: https://github.com/rubberduck-vba/rubberduck/wiki/IoC-Container Register an already existing instance within the IoC container. Such registrations always behave as singletons, regardless of the specified lifestyle, ensuring that the provided instance is always returned. ```csharp container.Register(Component.For().Instance(_vbe)); ``` -------------------------------- ### Configure Statistical Functions Source: https://github.com/rubberduck-vba/rubberduck/blob/next/RubberduckTests/Testfiles/Grammar/Reference_Module_6.txt Configures a tyStatFns object with various statistical options and NV pairs for parameters like DecimalPlaces and ExcludeZeros. Uses GetNV to create the parameter NV pairs. ```VBA Public Function GetStatFns(Optional Min As Boolean _ , Optional Avg As Boolean _ , Optional wAvg As Boolean _ , Optional Max As Boolean _ , Optional DecimalPlaces As Variant _ , Optional ExcludeZeros As Variant _ , Optional NoDataHeader As Variant _ , Optional NoFieldHeader As Variant _ ) As tyStatFns Const ThisProcedure As String = ThisModule & "|GetStatFns|Function" Dim ltStatFns As tyStatFns With ltStatFns .Min = Min .Avg = Avg .wAvg = wAvg .Max = Max .DecimalPlacesNV = GetNV(Name:=ConParDecimalPlaces, Value:=DecimalPlaces) .ExcludeZerosNV = GetNV(Name:=ConParExcludeZeros, Value:=ExcludeZeros) .NoDataHeaderNV = GetNV(Name:=ConParNoHeader, Value:=NoDataHeader) .NoFieldHeaderNV = GetNV(Name:=ConParNoHeader, Value:=NoFieldHeader) End With GetStatFns = ltStatFns End Function ```