Function String Extras Class

KeepVBComments

"Keep Visual Basic Comments" Retain the comments within a string representing a line of Visual Basic code. Returns a string containing the comment portion from a line of Visual Basic source code.

Signature (Visual Basic / VBA)

Public Function KeepVBComments( _
      ByVal vLine As Variant _
    , Optional ByVal vKeepLeadingSpaces As Variant _
    ) As Variant

Code Example

    KeepVBComments("    ' Assignment.") = "' Assignment."
    KeepVBComments("    ' Assignment.", True) = "    ' Assignment."
    KeepVBComments("    lngNum = 45 ' Assignment.") = "' Assignment."
    KeepVBComments("    lngNum = 45 ' Assignment.", True) = "    ' Assignment."
    KeepVBComments("    lngNum = 45") = ""

Parameters

Parameter Description
vLine The string containing a line of Visual Basic source code. Function returns Null if vLine is Null or cannot be fixed up to a String.
vKeepLeadingSpaces Determine whether the spaces which precede any comments will be retained. True if leading spaces should be copied to the result string, and False if leading spaces should be ignored. vKeepLeadingSpaces defaults to False if it is missing or Null or cannot be fixed up to a number.