The idea behind this example is to extract comments from a Visual Basic code file so you can spellcheck them. This is a fairly simple, manual approach. Some commercial products can spellcheck comments and strings for you.
Function ExtractComments reads a Visual Basic file stored in a string and returns a string containing its comments.
The function starts by removing line continuation characters (" _") followed by a vbCrLf. This joins continued lines.
Next the code splits the file into lines. It calls function FirstCodeLine to find the first line in the file that is actual code. The program then loops through the lines containing code.
For each line, the program loops through the line's characters. When it finds a double quote character, the code toggles the Boolean variable quote_open to remember whether it is inside a quoted string.
When it finds a single quote character, the code checks quote_open to see if the character is inside a quoted string. If it is not, then the function adds the rest of the line to the result string and exits the inner For loop so it goes to check the next line.
After it has checked every line, the function returns the result it has built.
|