Results 1 to 11 of 11
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code: VBE put to use

    Well, Chris has got me going on posting code. Here's my contribution to the library. <img src=/S/2cents.gif border=0 width=15 height=15>

    This is a handy sub that counts the lines in a project and puts the total in the header of a code module named Startup. I count comments, but you can modify the code to skip comment lines if you want. It also removes those pesky blank lines from the top of code mods. I learned the Dev v. production technique from an old Robin Trew post. The gist is if you want intellisense and the object model help, you need a reference to the VBE extension library. Once you've nailed it down, you don't!

    <pre>Sub CountMyLines()
    Dim lTotal As Long

    #Const mDeveloping = False
    #If mDeveloping Then
    Dim aComp As VBComponent
    Dim DocComps As VBComponents
    #Else
    Dim aComp As Object
    Dim DocComps As Object
    #End If

    lTotal = 0
    Set DocComps = ActiveDocument.VBProject.VBComponents
    'While counting lines of code, remove the blank line if it exists from each form code pane
    For Each aComp In DocComps
    If Left$(aComp.Name, 3) = "frm" Then
    While aComp.CodeModule.Lines(1, 1) = ""
    aComp.CodeModule.DeleteLines (1)
    Wend
    End If
    lTotal = lTotal + aComp.CodeModule.CountOfLines
    Next
    With Application.VBE.ActiveVBProject.VBComponents
    .Item("Startup").CodeModule.InsertLines 11, "' Total Line Count: " + CStr(lTotal)
    .Item("Startup").CodeModule.DeleteLines (12)
    End With
    'MsgBox "Total lines in this app: " + CStr(lTotal)

    End Sub
    </pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Kevin,

    Two quick thoughts:

    1. Checking for a form relies on your naming convention. Is there a way to do it without relying on the naming convention?

    2. How do you use this? I don't have a use for knowing how many lines of code myself- the last time I needed that was for Y2K planning.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    1. Relies on either the naming convention or the index number of the code mod. Either way, you must verify the reference is to the module you want (what happens when you add a mod before the one referenced? The reference changes. I'd rather see the name than a number.

    2. This code has no compelling use execpt to be able to answer the question, "So how big is that app you're working on now?" I can say, "Oh it's ballonned to about 5500 lines." To which they say, "Oh, really?" Then we all take another sip of coffee and go on with our day. <img src=/S/doze.gif border=0 width=15 height=15>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    In answer to point 2:

    That sounds a good enough reason. I'll take 10 copies of the routine please.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    You made me laugh <img src=/S/laugh.gif border=0 width=15 height=15>

    "A joyful heart is good medicine..."

    And let's not forget that little routine demonstrates in a easy going kinda fashion how to poke around the VBE objects. Some of 'em anyway.

    10 copies come to $.10. Would like them gift wrapped?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Of those 5,500 lines, at least 1,000 are dead wood - procedures you no longer use.

    Why not try my Procedure Stripper - no Kevin, nothing to do with seven veils - which

    (1) Removes unreferenced procedures from a WordVBA template
    (2) Sorts procedures in alphabetic sequence in each module
    (3) More (you can copy code bodies to clipboard etc.)

    Ask nicely and I'll email you a copy.

    The REAL bonus for me is that if a client asks for ALL the source code for an application, I can strip out 90% of my utils code that isn't really needed. They get some good stuff, but only the 10% they need for the particular appliaction.

    I create an application by dragging code modules into a template. ProcStripper lets me remove what I didn't know I didn't need.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Chris,

    ProcStripper sounds good. Post or email away! I'd love to try it.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Sure. What's a good email address (besides Geoff.Whitfield@Sheep.Station?).

    I'd like to email you a copy; if you can get it working I'll post it here and/or U/l it to my web site.

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Chris,

    Send it to the right person (although you can send one to me as well).

    You replied to Kevin@home.alone
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    Lounger
    Join Date
    Mar 2001
    Location
    LA, California, USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Would you mind sending me a copy, too? I have some code that someone else wrote and I would like to get rid of "dead wood." Just click on my name for the e-mail.
    Thanks

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Code: VBE put to use

    Hi Chris,

    This sounds like excellent code. Can I beg a copy as well?

    karen@premier.net.nz

Posting Permissions

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