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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds