Macro That Opens Resource File as Text

While this certainly isn't the most difficult of sequences it simply cries out to be automated. Therefore, in this article, I present you with a very simple macro that automates the entire process of opening a resource file in "text mode". Enjoy!

Code

'------------------------------------------------------
'FILE DESCRIPTION: Open Current Resource Script As Text
'------------------------------------------------------
sub OpenRCAsText()
'DESCRIPTION: Open Current Resource Script As Text
'AUTHOR: Roman A. Surma <xaos@mail.ru>

 if Windows.Count > 0 then

  rc_name = ActiveDocument.FullName

  if InStrRev( rc_name, ".rc" ) > 0 then
  'if we have .rc file - let's open it as text

   rc_wnd_name = ActiveWindow.Caption

   Documents.Open rc_name, "Text"

   'performing primitive search for resource in .rc file
   'TODO: enhance algorithm to search resource in proper
   'language section
   rc_part         = ".rc - "

   res_name_start  = InStr( rc_wnd_name, rc_part ) 
                   + Len( rc_part )

   res_name_end    = InStr( res_name_start, rc_wnd_name, " " )

   if res_name_end > res_name_start then

    res_name = Mid( rc_wnd_name, res_name_start, 
     res_name_end - res_name_start )

    'searching for regexp like "^ *IDD_DIALOG1"
    ActiveDocument.Selection.FindText "^ *" & res_name, 
     dsMatchFromStart + dsMatchRegExp

    'ActiveDocument.Selection.Cancel

    ActiveDocument.Selection.StartOfLine
   end if

  end if
 elseif Documents.Count >= 1 then
  rc_name = ActiveProject.FullName

  dot_pos = InStrRev( rc_name, "." )

  rc_name = Left( rc_name, dot_pos ) & "rc"

  on error resume next

  Documents.Open rc_name, "Text"

  if Err.Number < 0 then

   MsgBox( "Can not open resource file " & rc_name & " _
    "for this project: " & ActiveProject.Name )

  end if

  on error goto 0
 end if

end sub

Downloads

Download source (same code as above) - 1 Kb


Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds