View Single Post
  #5   Report Post  
scattered
 
Posts: n/a
Default

Amit,
I came up with the following code. To use it you could first enter
the code in a standard module called ToDo, export the module and then
import the module into any project you want.
You need to include a reference to the Microsoft Visual Basic for
Applications Extensibility library in any project that uses it. I am
using Excel 2000 in Windows XP. If your configuration is different
there is a potential for incompatibilities. The comment in the code
explains how to use it. It picks out comment blocks whose first line
begins 'ToDo or 'To do. Subsequent lines don't need to begin with a
Todo. Note that anything like

av = sum/num 'to do: handle case div by zero

would have to be rewritten as
av = sum/num
'to do: handle case div by zero

or it would be missed. At the cost of a little more parsing you could
remove that restriction if you want to.

Here is a sample output:
--------------------------------------------------
ToDo list for VBAProject(TSP.xls)
--------------------------------------------------
1) ThisWorkbook, Line 3:
to do: debug this stupid thing

2) Sheet1, Line 334:
To do: get a better sort routine
This one isn't much better than bubble sort

3) Sheet1, Line 644:
todo: find exact solution

4) Module1, Line 2:
todo: nothing

5) ToDo, Line 71:
Todo: decide if you want to strip leading
spaces from a ToDo block line or leave the
indenting. The code as written strips spaces

6) ToDo, Line 85:
to do: it would be nice to be able to assign priorities
to the to dos and then sort them

The code:
__________________________________________________ ___

Option Explicit

'This module is designed to implement a simple VBE ToDo list
'
'The ToDos are represented by comment blocks (contiguous blocks of
comment
'lines) in which the first line begins with "To do" or "ToDo".
'Note that the ToDo block must start with a complete comment line.
'The output of the program is printed to the Immediate Window,
'but it would be easy to modify to print to a text file as well.
'To use this type "ToDoList" in the immediate window from anywhere
'in the project. Type "ToDoList False" to localize the list to
'component whose code window you are currently viewing
'
'Make Sure to include a reference to the Microsoft VBA Extensibility
'Library in your project in tools-references.

Private toDoCount As Long

Sub ToDoList(Optional ListAll As Boolean = True)
Dim myVBE As VBIDE.VBE
Set myVBE = Application.VBE
Dim myProj As VBIDE.VBProject
Set myProj = myVBE.ActiveVBProject
Dim cmp As VBIDE.VBComponent
Dim myName As String
Dim A As Variant

A = Split(myProj.Filename, "\")
myName = A(UBound(A))

toDoCount = 0
Debug.Print String(50, "-")
Debug.Print "ToDo list for " & myProj.Name _
& "(" & myName & ")"
Debug.Print String(50, "-")
If ListAll Then
For Each cmp In myProj.VBComponents
Check cmp
Next cmp
Else
Set cmp = myVBE.ActiveCodePane.CodeModule.Parent
Check cmp
End If

If toDoCount = 0 Then Debug.Print "No items to display"

End Sub

Sub Check(cmp As VBIDE.VBComponent)
Dim i As Long, n As Long
Dim codeLine As String
Dim ToDo As String
Dim myCode As VBIDE.CodeModule
Set myCode = cmp.CodeModule

n = myCode.CountOfLines
i = 1
Do While i <= n
codeLine = LTrim(myCode.Lines(i, 1))
If Not codeLine Like "'*" Then 'not a candidate
i = i + 1
Else
If UCase(LTrim(Mid(codeLine, 2))) Like "TO DO*" Or _
UCase(LTrim(Mid(codeLine, 2))) Like "TODO*" Then
'In a ToDo block!
toDoCount = toDoCount + 1
Debug.Print toDoCount & ") " & cmp.Name _
& ", Line " & i & ":"
Do While i <= n And LTrim(codeLine) Like "'*"
Debug.Print Mid(LTrim(codeLine), 2)
'Todo: decide if you want to strip leading
'spaces from a ToDo block line or leave the
'indenting. The code as written strips spaces
i = i + 1
If i <= n Then codeLine = myCode.Lines(i, 1)
Loop
Debug.Print " " 'this triggers a blank line
Else
i = i + 1
End If
End If
Loop
End Sub

'to do: it would be nice to be able to assign priorities
'to the to dos and then sort them

__________________________________________________ ____________

Hope this helps
- John (aka scattered - you should see my desk)