Skip to content

Commit bb03b45

Browse files
committed
closes #436
1 parent 3a48387 commit bb03b45

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

RetailCoder.VBE/Extensions/VbeExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ public static class VbeExtensions
99
{
1010
public static void SetSelection(this VBE vbe, QualifiedSelection selection)
1111
{
12-
//not a very robust method. Breaks if there are multiple projects with the same name.
1312
var project = vbe.VBProjects.Cast<VBProject>()
14-
.FirstOrDefault(p => p.Protection != vbext_ProjectProtection.vbext_pp_locked
15-
&& p.Equals(selection.QualifiedName.Project));
13+
.FirstOrDefault(p => p.Protection != vbext_ProjectProtection.vbext_pp_locked
14+
&& p.Equals(selection.QualifiedName.Project));
1615

1716
VBComponent component = null;
1817
if (project != null)
1918
{
2019
component = project.VBComponents.Cast<VBComponent>()
21-
.FirstOrDefault(c => c.Equals(selection.QualifiedName.Component));
20+
.FirstOrDefault(c => c.Equals(selection.QualifiedName.Component));
2221
}
2322

2423
if (component == null)

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ public override IDictionary<string, Action<VBE>> GetQuickFixes()
2626

2727
private void DeclareAsExplicitVariant(VBE vbe)
2828
{
29-
var component = FindComponent(vbe);
30-
if (component == null)
31-
{
32-
throw new InvalidOperationException("'" + QualifiedName + "' not found.");
33-
}
34-
35-
var codeLine = component.CodeModule.get_Lines(QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.LineCount);
29+
var codeModule = QualifiedSelection.QualifiedName.Component.CodeModule;
30+
var codeLine = codeModule.get_Lines(QualifiedSelection.Selection.StartLine, QualifiedSelection.Selection.LineCount);
3631

3732
// methods return empty string if soft-cast context is null - just concat results:
3833
string originalInstruction;
@@ -49,7 +44,7 @@ private void DeclareAsExplicitVariant(VBE vbe)
4944
}
5045

5146
var fixedCodeLine = codeLine.Replace(originalInstruction, fix);
52-
component.CodeModule.ReplaceLine(QualifiedSelection.Selection.StartLine, fixedCodeLine);
47+
codeModule.ReplaceLine(QualifiedSelection.Selection.StartLine, fixedCodeLine);
5348
}
5449

5550
private string DeclareExplicitVariant(VBAParser.VariableSubStmtContext context, out string instruction)

0 commit comments

Comments
 (0)