Simple File purpose comment macro

.

Environment: Visual C++ 6.0

Simple VC++ 6.0 macro to add a comment to a file

It is a good practice to have a header for each file in a project describing the contents ,purpose and modifications made. This simple macro will take reduce typing by filling up the necessary data to the header.It will pop up a dialog box asking for the purpose of the file.

To intall the macros copy both files into a macro file(it can be opened by going to tools->macros and select a file in the combo or create new file and select edit) and for ease of use make a tool bar button for the macro.



'------------------------------------------------------------------------------
'FILE DESCRIPTION: A simple macro to give file comments
'------------------------------------------------------------------------------


Sub FileC()
'DESCRIPTION: File Comments. - karthiksundar 
' check if any file is open 
	if (Windows.Count = 0) then
		MsgBox ("No file opened to comment")
		exit sub
	end if 
'Check if this is a CPP file
	if (FileType (ActiveDocument) = FALSE) then
		exit sub
	end if

	ActiveDocument.save
	File_Name = ActiveDocument.ActiveWindow.Caption

'macro starts here
	'Get the purpose of the function  from the user
	Purpose = InputBox("what is the Purpose of " & File_Name ,"Purpose of File",File_Name)
	if (Purpose = "") then
		exit sub
	End if
	Purpose = "Purpose		    : "+ Purpose
	ActiveDocument.Selection.StartOfDocument
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection.LineUp
	ActiveDocument.Selection = "/******************************************************************************************"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "FileName		: " & File_Name
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "Author			: your name here"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = Purpose
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "Date Of Creation: "& date
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "Modification History :"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "Date             Modifications"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "******************************************************************************************/"
	ActiveDocument.Selection.NewLine
	ActiveDocument.save
	'End Recording
End Sub

Function FileType (ByVal doc)
	
	ext = doc.Name
	pos = Instr(ext, ".")
	if pos > 0 then
		Do While pos <> 1
			ext = Mid(ext, pos, Len(ext) - pos + 1)
			pos = Instr(ext, ".")
		Loop
		ext = LCase(ext)
	end if
	
	if ext = ".c" Or ext = ".cpp" Or ext = ".h"Then
		FileType = TRUE
		exit function
	else
		MsgBox ("This is not a "".cpp "","".c"","".h"" file")
		FileType = FALSE
	end if
End Function

Date Last Updated: February 3, 1999



Comments

  • Automatic insertion of the author's name?

    Posted by Legacy on 06/24/1999 12:00am

    Originally posted by: Andreas Jaeger

    It would be helpfull to allow the macro to retrieve the user name from the operation system (login name or similar) and use it in this macro. I have tried it, but was not successfull. Knows anybody how to do it?

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

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds