Macro for Visual Studio switching between CPP and header files (Alt + O)

Source: Internet
Author: User
Macro for Visual Studio switching between CPP and header files (Alt + O)

(See link: http://www.codeproject.com/KB/macros/SourceHeaderJumper.aspx)

Introduction

How many times C/C ++ programmer swaps between source and header files? Hundreds times per a day! Simple Macros in DTE essentially accelerates swapping action.
Create new module, or use existing one, in my case "commonmacros". To convenience, It is necessary link up this macros to hot key, see picture.


 

Macros code

CollapseCopy code

    
Option Explicit On
Imports Envdte

 

Public Module Commonmacros
Sub Sourceheaderjumper ()
' Splitted file name

Dim Sarr As System. Array
' New filename generated by macros

Dim Newfn As String
' File Name base (without extention)

Dim Fnbase As String
' File extention

Dim EXT As String
' Simple counter

Dim I As Integer

If DTE. activedocument () is nothing then
exit sub
end If
Sarr = DTE. activedocument (). name (). split (" . ")
' has file extention?

If (Sarr. getlength ( 0 ) 2 ) then
exit sub
end If

'File Name Base

Fnbase = DTE. activedocument (). Path ()
ForI =0 ToSarr. getlength (0)-2
Fnbase = fnbase + Sarr (I) +"."
Next

'File extention

EXT = system. Convert. tostring (Sarr. getlength (0)-1). Tolower ()

' Business Logic

If (EXT =" CPP" ) Or (EXT = " C" ) Then
Newfn = fnbase + " H"
Else
If EXT = " H" Then
Newfn = fnbase + " CPP"
If Not System. Io. file. exists (newfn) Then
Newfn = fnbase + " C"
End If
End If
End If

'If you don't want add file to tabs uncomment next line

'DTE. activedocument (). Close ()

'Opens needed File

IfSystem. Io. file. exists (newfn)Then
DTE. itemoperations. openfile (newfn)
End If
End Sub

End Module

Conclusion

Try this feature, this macros will save hours of you time during programming from month to month.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.