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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • Live Event Date: November 18, 2014 @ 11:00 a.m. EST As you embrace the hybrid world of on-premise and cloud applications, often accessed via mobile devices, you now have to be concerned that cybercriminals have yet another vehicle to attack your business. In fact, the average cost of cybercrime has increased over 10% in the last year, and this applies to businesses of all sizes. Attend this webinar to hear David Monahan, Security Research Director at EMA, and Dana Epp, recognized security luminary from …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds