In a previous post I wrote about switching between header and impl files in .NET, and I referred you to a codeproject page with some VB script that does the switching. The code on codeproject assumes that the files reside in the same directory, which isn’t always the case. Here’s some slightly improved code.. It fits my needs anyways.. 🙂
Option Strict Off
Option Explicit Off
Imports EnvDTE
Imports Microsoft.VisualBasic
Public Module Switch
Sub Switch()
Dim a As String
Dim b As String
Dim Flag As Integer
Flag = 0
a = DTE.ActiveDocument.Name()
tmp = InStr(a, ".cpp")
If tmp Then
b = Left(a, Len(a) - 3) + "h"
Flag = 1
Else
tmp = InStr(a, ".hh")
If tmp Then
b = Left(a, Len(a) - 2) + "cc"
Flag = 1
Else
tmp = InStr(a, ".cc")
If tmp Then
b = Left(a, Len(a) - 2) + "hh"
Flag = 1
Else
tmp = InStr(a, ".h")
If tmp Then
b = Left(a, Len(a) - 1) + "cpp"
Flag = 1
End If
End If
End If
End If
If Flag Then
DTE.Solution.FindProjectItem(b).Open()
End If
End Sub
End Module