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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds