VB 6.0 - CodeModule.InsertLine - Asked By Rusty on 13-Oct-11 11:24 AM

Earn up to 10 extra points for answering this tough question.
I am able to insert a line of code underneath a module name (Sub or Function) but I need to include the contents of a variable.

Dim objModule as CodeModule
Dim objProject as VBProject
Dim objMember as Member

Set objModule = objProject.VBComponents(objComponent.Name).CodeModule
For Each objMember In objModule.Members
  
  [I check to see if the current member is a Method, if it is I code]
  objModule.InsertLines lngInsertLine + 1, "debug.print " & objMember.Name

Next

In whatever VB6 project I use to test the add-in I get the name of the module so I insert Debug.Print Func1. Whoever this will cause an error because VB6 will look for a element called Func1. I am trying to add double quotes (") at the begining of the method name and the end so each time the particular method is hit, Debug.Print [Method name] will be in the immediate window. I have tried but I get Debug.Print objMember.Name.

Can somone please help?
Asked By Rusty on 14-Oct-11 09:52 AM
I am dealing with several Visual Basic 6 programs that the guy who wrote it went out of his way to make it difficult to follow thinking he would have a job forever. In a sense it worked, most others, even though they are very well versed in VB, throw there hands up in disgust and run away. I however do not run from a challange.
 
What has helped is to map the program by putting Debug.Print statments in every module so we have a roadmap of where the program goes. I found a work around I am not really happy with, I put symbols like #$%^ in front of and behind ObjMember.name in order to do a search for #$%^ and replace everyone with a ".

I will try what you have above but I ran into another problem. Debug.Print ObjMember.name is inserted into the module but if the person who wrote the module did somthing like this:

Private Sub MySub(Parameter1, _
  Paremeter2, _
  Parameter3)

The statment is inserted like this:

Private Sub MySub(Parameter1, _
  Debug.Print ObjMember.Name
  Paremeter2, _
  Parameter3)

This of course will cause an error. I get the code line where the module begins and add 1 to it. This works well except for the situation above. Any ideas?