CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Lines of Code

  1. #1
    Join Date
    Aug 2000
    Location
    india
    Posts
    191

    Lines of Code

    Hi,

    In a VB project, how to get the total lines of code? Is there any method or tool to count?

    Thanks in advance.


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Lines of Code

    There are some programs or add-ins that can do this. This one for instance
    http://www.planetsourcecode.com/xq/A...s/ShowCode.htm

    Tom Cannaerts
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Aug 2000
    Location
    india
    Posts
    191

    Re: Lines of Code

    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.


  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Lines of Code

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Lines of Code

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  6. #6
    Join Date
    Aug 2000
    Location
    india
    Posts
    191

    Re: Lines of Code

    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?


  7. #7
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Lines of Code

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  8. #8
    Join Date
    Aug 2000
    Location
    india
    Posts
    191

    Re: Lines of Code

    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?




  9. #9
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Lines of Code

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  10. #10
    Join Date
    Aug 2000
    Location
    india
    Posts
    191

    Re: Lines of Code

    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.


  11. #11
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Lines of Code

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured