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

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds