function()
{
    /*
        被注释掉的代码    //可以注释掉
     */}一般是上面的方法,但是,当被注释掉的代码中有/*...*/比如:
function()
{
    /* 
        .........
        其它代码
        ........
        /*
        想注释掉的代码     //可是注释不掉
        */        .........
        其它代码
        ........
     */}
那么就会有代码注释不掉,我记得我看过一种方法可以,就是忘了,哪位大哥知道,言一声,谢谢了

解决方案 »

  1.   

    你可以使用条件编译的方法来注释代码:
    #if 0
    ...
    ...
    ...
    #endif
    就可以了!!!
      

  2.   

    一楼的办法,条件编译
    #if 0
    不需要的代码
    #endif
      

  3.   

    给你一个宏,怎么用不必说了吧。
    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 = ".rc" Or ext = ".rc2" Then
    FileType = 4
    ElseIf doc.Language = dsCPP Then
    FileType = 1
    ElseIf doc.Language = dsJava Then
    FileType = 2
    ElseIf doc.Language = dsIDL Then
    FileType = 3
    ElseIf doc.Language = dsHTML_IE3 Or doc.Language = dsHTML_RFC1866 Then
    FileType = 5  
    ElseIf doc.Language = dsVBSMacro Then ' 
    FileType = 6  
    ElseIf ext = ".def" Then
    FileType = 7
    Else 
    FileType = 0
    End If 
    End FunctionSub CommentOut ()
    'DESCRIPTION: Comments out a selected block of text.
    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)  
        CommentType="//"
         
    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 = CommentType + ActiveDocument.Selection Else 
    For i = StartLine To EndLine
    ActiveDocument.Selection.GoToLine i
    ActiveDocument.Selection.SelectLine
    ActiveDocument.Selection = CommentType + _
    ActiveDocument.Selection
    Next
    End If
    End If
    End SubSub CommentIn ()
    'DESCRIPTION: Comments in a selected block of text.
    Dim win
    Dim temptxt
    set win = ActiveWindow
    if win.type <> "Text" Then
      MsgBox "This macro can only be run when a text editor window is active."
    else
      
    StartLine = ActiveDocument.Selection.TopLine
    EndLine = ActiveDocument.Selection.BottomLine
    If EndLine < StartLine Then
    Temp = StartLine
    StartLine = EndLine
    EndLine = Temp
    End If If EndLine = StartLine Then
    temptxt =Ltrim(ActiveDocument.Selection)

    count=Len(temptxt)
    if count>2 then
        temp1=left(temptxt,2)
                                         if temp1="//" then
              ActiveDocument.Selection=Right(temptxt,count-2)
    end if
                                    end if
    Else 
    For i = StartLine To EndLine
    ActiveDocument.Selection.GoToLine i
    ActiveDocument.Selection.SelectLine
    temptxt =Ltrim(ActiveDocument.Selection)
          count=Len(temptxt)
        if count>2 then
            temp1=left(temptxt,2)
                                            if temp1="//" then
                ActiveDocument.Selection=Right(temptxt,count-2)
    end if
                                         end if
    Next
    End If
    end if
      
    End Sub
    格式有点乱,将就点吧:)
      

  4.   

    if 0
    endif;)不过这样不直观,但是方便
      

  5.   

    function()
    {
        /* 
            .........
            其它代码
            ........
            ///*
            想注释掉的代码     //可是注释不掉
            //*/        .........
            其它代码
            ........
         */}
      

  6.   

    去codeproject下载注释宏,很好用。