Click to See Complete Forum and Search --> : Lines of Code
shashidharkr
September 20th, 2001, 12:27 AM
Hi,
In a VB project, how to get the total lines of code? Is there any method or tool to count?
Thanks in advance.
Cakkie
September 20th, 2001, 01:15 AM
There are some programs or add-ins that can do this. This one for instance
http://www.planetsourcecode.com/xq/ASP/txtCodeId.7026/lngWId.1/qx/vb/scripts/ShowCode.htm
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
shashidharkr
September 20th, 2001, 01:49 AM
Thank you Cannaerts.
Just to check this program, I created a dummy project. This project contains single form. Code of the project is shown below:
private Sub Form_Load()
' message box
MsgBox "hai"
End Sub
As you can see, there are only 4 lines of code, including the comment. But when I run the program code count.exe, I am getting the No. of lines as 21. Program shows the count of forms, modules, class modules and user modules correctly. But count No. of lines is not correct.
Is there any other addins or programs which gives the correct result?
Thanks in advance.
Cakkie
September 20th, 2001, 01:53 AM
Sorry, I didn't test the software, but what I suspect is that it counts the lines in the form file, in stead of the actual number of lines. If you oopen the form in notepad, you will probably count 21 lines. I will get into this deeper, so I'll be in touch.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Cakkie
September 20th, 2001, 02:03 AM
Ok, I checked it out, and came up with this:
Create a new project, and select add-in
In the form, paste following code in the cmdOK_Click event
private Sub OKButton_Click()
Dim Cmp as VBComponent
Dim lCount as Long
for Each Cmp In VBInstance.VBProjects(1).VBComponents
lCount = lCount + Cmp.CodeModule.CountOfLines
next Cmp
MsgBox "The number of lines is: " & lCount
End Sub
Now press play (or compile it into an add-in, fire up another version of VB, open a project, select Add-ins>Add-in manager. Make sure the status of 'My Addin' says starup/loaded. In the Add-In menu, select 'My Addin', and press the OK button. You should see the nuimber of lines.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
shashidharkr
September 20th, 2001, 02:34 AM
You are right. When form is opened in text file, it has 21 line. But this includes properties also. So, it is 17 lines of properties and 4 lines of code. But I think this is not correct to include properties also. What do you say?
Cakkie
September 20th, 2001, 02:41 AM
I wouldn't include those lines, it gives a wrong idea. Ok, if you have a 50000 lined project, a few hundred lines more or less don't make the difference, but it is always nice to know the exact number.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
shashidharkr
September 20th, 2001, 03:16 AM
Thank you.
I could compile an addin as per the code given by you with the name CountOfLines.exe. But, when I open a new project, I could not see this addin the addin manager. Also, where should I set the status as startup / loaded?
Cakkie
September 20th, 2001, 03:28 AM
When designing the add-in, double click 'Connect' in the project explorer. On the form, select the tab 'Advanced'. For application, select 'Visual Basic', For version select 'Visual Basic X' where X is the version of VB you are using. For initial load behaviour, select 'Startup'. Switch to code view, there should be a line somwhere looking like this:
Set mcbMenuCommandBar = AddToAddInCommandBar("My AddIn")
Change it to
Set mcbMenuCommandBar = AddToAddInCommandBar("Your add-in name here")
This is how it will show up in the addin window.
Recompile the dll, exit VB, and restart it. Open a new or existing project, and check the Add-ins menu, the add-in should be there, or at least listed in the Add-in maganer.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
shashidharkr
September 20th, 2001, 05:02 AM
Thank you.
I am using VB5.0. I could get 'Connect', but not the 'Advanced' tab. Can you please make it more clear about where you get 'Version' and 'Startup'. I got other things right.
Cakkie
September 20th, 2001, 05:27 AM
I checked, and indeed, in VB5 those things aren't there. The connect is a class there, where in VB6 it is a designer. I guess you then need to set the load behaviour via the add-in manager.
I don't even know if those things affect the add-in, I assume the load behaviour does, but the version doesn't.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.