你編程序時肯定遇到要一次爲很多行代碼加註釋的情況,以前我都是一行行的加“!”,今天偶然在一個論壇上看到一個解決方案,而且自己按照他的方法,試驗了一下,證明切實可行!
現與大家分享:aaaaaa
不止一位問道可不可以在visual fortran中爲多行代碼加註釋。
visual fortran本身無這樣的功能,但是可以用macro功能自己添!而且是添加工具鈕!
做法:
(1) 在..\Microsoft Visual Studio\Common\MSDEV98\MACROS文件夾下生成文件GrpComment.dsm
(2) 用文本編輯器打開該文件,將以下所附的代碼貼在其中,保存(注意保留.dsm後綴)
(3) 啓動CVF,選Tools=>Customize=>Add-ins and Macro Files
(4) 在GrpComment前打勾,去掉其他的勾
(5) 在同一對話框中選Commands=>Macros,此時在右邊可以看見CommentDel和CommentOut
(6) 選中CommentOut,拖到CVF的工具欄上去(添加工具鈕),會彈出Button Appearance對話框
(7) 選Image and text,在下邊Button text框中輸入名稱(默認是CommentOut),如“加註釋”
(8) 類似的方法再將CommentDel命令以工具鈕的形式添加到工具欄上,名稱可取爲“去註釋”
這時,工具欄上應該多了兩個工具鈕:“加註釋”和“去註釋”。
用法:
加註釋:選擇要加註釋的多行代碼,點擊“加註釋”按鈕即可;
去註釋:選擇已經註釋的多行代碼,點擊“去註釋”按鈕即可。
適用:後綴爲f90或f77的代碼文件。
Enjoy!!!
VBscript代碼:
Function FileType (ByVal doc)
ext = doc.Name
FileType = 0
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 = ".f90" Then
FileType = 8
ElseIf ext = ".for" Then
FileType = 9
Else
FileType = 0
End If
End Function
Sub CommentOut ()
'DESCRIPTION: 爲所選的多行代碼加註釋
Dim win
set win = ActiveWindow
if win.type <> "Text" Then
MsgBox "This macro can only be run when a text editor window is active."
else
TypeOfFile = FileType(ActiveDocument)
If TypeOfFile = 8 Or TypeOfFile = 9 Then
If TypeOfFile = 8 Then
CommentType = "! " ' Fortran 90 file
Else
CommentType = "C " ' Fortran 77 file
End If
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
If EndLine < StartLine Then
Temp = StartLine
StartLine = EndLine
EndLine = Temp
End If
If EndLine = StartLine Then
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection = CommentType + ActiveDocument.Selection
Else
For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection = CommentType + _
ActiveDocument.Selection
Next
End If
else
MsgBox("Unable to comment out the highlighted text" + vbLf + _
"because the file type was unrecognized." + vbLf + _
"If the file has not yet been saved, " + vbLf + _
"please save it and try again.")
End If
End If
End Sub
Sub CommentDel ()
'DESCRIPTION: 去除所選的多行代碼的註釋
Dim win
set win = ActiveWindow
if win.type <> "Text" Then
MsgBox "This macro can only be run when a text editor window is active."
else
TypeOfFile = FileType(ActiveDocument)
If TypeOfFile = 8 Or TypeOfFile = 9 Then
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
If EndLine < StartLine Then
Temp = StartLine
StartLine = EndLine
EndLine = Temp
End If
If EndLine = StartLine Then
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection = mid(ActiveDocument.Selection, 3)
Else
For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i
ActiveDocument.Selection.SelectLine
ActiveDocument.Selection = mid(ActiveDocument.Selection, 3)
Next
End If
else
MsgBox("Unable to comment out the highlighted text" + vbLf + _
"because the file type was unrecognized." + vbLf + _
"If the file has not yet been saved, " + vbLf + _
"please save it and try again.")
End If
End If
End Sub
fortran 多行註釋
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.