Get Friend File

Macro that opens the corresponding .h / .cpp file (i.e. if fnurt.h is active it opens fnurt.cpp and vice verca) and works best if used via a accelerator key (using Alt-1 myself).

Quite lo-tech but useful never the less.


Sub GetFriendFile()
'DESCRIPTION: Opens the corresponding .h / .cpp file

 currentFileName = Application.ActiveDocument.FullName
 newFileName = ""

 if (Ucase(Right(currentFileName,2))=".H") then
   newFileName = Left(currentFileName,Len(currentFileName)-2)+".CPP"
 elseif (Ucase(Right(currentFileName,4))=".CPP") then
   newFileName = Left(currentFileName,Len(currentFileName)-4)+".H"
 end if

 if newFileName<>"" then Application.Documents.Open newFileName

End Sub

Date Last Updated: February 3, 1999



Comments

  • Added Error Processing

    Posted by Legacy on 04/03/2000 12:00am

    Originally posted by: Mark Jordan

    I added error handling and this macro no longer blows up if the corresponding file doesn't exist.
    
    

    currentFileName = Application.ActiveDocument.FullName
    newFileName = ""

    if (Ucase(Right(currentFileName,2))=".H") then
    newFileName = Left(currentFileName,Len(currentFileName)-2)+".CPP"
    elseif (Ucase(Right(currentFileName,4))=".CPP") then
    newFileName = Left(currentFileName,Len(currentFileName)-4)+".H"
    end if

    on error resume next
    if newFileName <> "" then
    Application.Documents.Open newFileName
    if (err <> 0) then
    msgbox "Error opening corresponding file - " & err.description
    end if
    end if

    Reply
  • improved version of the above

    Posted by Legacy on 12/02/1999 12:00am

    Originally posted by: Amir Lopatin

    This macro will also open up the cpp from the h and 
    
    vice versa but in addition, it also places them side
    by side:

    Function CloseExceptActive ()
    'DESCRIPTION: Closes all editor windows except the current one.

    'Windows.Item(1) is always the currently active window. So to close all
    ' the windows except the active one, keep looping until there is no
    ' longer a Windows.Item(2).
    do while Windows.Count > 1
    Windows.Item(2).Close(dsSaveChangesPrompt)
    Loop
    End Function


    Sub IsolateAndSplit()
    'DESCRIPTION: A description was not provided.
    CloseExceptActive ()
    fname= ActiveDocument.FullName
    s = Split(fname,".")
    preext =s(0)
    ext = s(1)

    if ext="cpp" Then
    alt=preext&".h"
    Else
    alt=preext&".cpp"
    End if

    Documents.Open alt, "Text"
    ExecuteCommand "WindowTileVertically"
    End Sub

    Reply
  • All "Toggle CPP/H" macros crash DevStudio

    Posted by Legacy on 02/03/1999 12:00am

    Originally posted by: Jean-Paul Retru

    I test all of macros who toggle between CPP and H files.
    All of them crash DevStudio 6.0.
    GetFriendFile too.

    I remember that the first test I do with these macros was with VC5.0 and DevStudio crash too.
    I think the crash is associated with MSDN viewer.

    Regards.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds