Results 1 to 22 of 22

Thread: VBTools AddIn - Auto indent VB code !

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    VBTools AddIn - Auto indent VB code !

    This is an Add-In I made that will show as a Toolbar in the VB IDE:


    The first button (and most usefull) will auto indent the currently opened code window.
    For example, you could have code like this:


    After you click the auto indent button, it will be like this:


    The second button displays the procedure list:


    I use the procure list to have a "preview" on what is in the selected code window. When you double click on a line, it will jump to that window, and also to the line number where the procedure starts.
    If you press "Ctrl+F", it will add the selected procedure to the "Favourites", you can add to favourites from any code window, and when you double click it will move the cursor to that procedure.

    I wanted to add more features, like adding line numbers, error control (but with more features/options than MZ-Tools), and also to remove uneccessary blank lines or add blank lines when there are none, but I never had the time to do it yet, so I thought to just post what I have until now, and I will update the post when I have a new version.

    Please post (tell me) when something is wrong, especially with the auto indenting code (if it does not indent properly).

    To get it to work, first compile the code, then add the add-in in the IDE from the "Add-In Manager"
    Attached Images Attached Images     
    Attached Files Attached Files
    Last edited by CVMichael; Jul 18th, 2007 at 08:35 AM.

  2. #2
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: VBTools AddIn - Auto indent VB code !

    Not 'wrong' as such, but more feature requests
    I currently use this addin to indent my code
    http://www.oaltd.co.uk/Indenter/Default.htm

    2 useful functions that it has are a context menu and the option to just indent a procedure rather than the whole module.

    Any chance of adding these?

    It might be an idea to put it in the project area and get more people to work on it.
    http://www.vbforums.com/forumdisplay.php?f=15

    I would like to replicate MZTools and try to improve on it.
    Its a shame that Carlos wont open source MZTools3.

  3. #3
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: VBTools AddIn - Auto indent VB code !

    Refactoring is something that I haven't been able to find in free VB6 addins.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VBTools AddIn - Auto indent VB code !

    What's Refactoring ?

    By the way... about your first post...
    I don't have time to make the changes you asked for, I'll try to do it when I find enough time for it.

    Maybe I should make a thread in Project Communication Area with a link to this thread instead of moving the whole thread ?
    Last edited by CVMichael; Jul 27th, 2007 at 10:52 AM.

  5. #5
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: VBTools AddIn - Auto indent VB code !

    Refactoring is renaming a variable in one place and having it renamed everywhere else (within the relevant scope).

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VBTools AddIn - Auto indent VB code !

    I actually wanted to do something like that, but I ran into problems when I could not get the hWnd handle of the Code Window (for subclassing)

    I have one more neat idea to add if I would be able to subclass the window. To integrate API into the IDE, for exaple, if i type in the code window "Private Declare " and as soon as I press the space bar, to show like the intellisense a list of all the APIs and while I type to search for a match that begins with what I typed... just like the intellisense... and also to have the option to automatically insert Types and constants for that particular API that I'm adding...
    Last edited by CVMichael; Jul 27th, 2007 at 11:10 AM.

  7. #7
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: VBTools AddIn - Auto indent VB code !

    There is source code here on how to make an extended search
    http://kandkconsulting.tripod.com/VB/VBCode.htm##AddIN
    You could incorporate it to bring VBTools closer to replacing MZTools

  8. #8
    Junior Member
    Join Date
    Jul 2008
    Posts
    23

    Re: VBTools AddIn - Auto indent VB code !

    Thank you for this tool, but unfortunately found an immediate bug.

    I need to create a very long absolute string for a tab-delimited file header. I may as well hard-code it as it will not change. This was done over a number of lines looking like the following:

    OutString = Item_Name & Chr(9) & _
    Item_Description & Chr(9) & _
    listing_id & Chr(9) & _
    seller_sku & Chr(9) & _
    Price & Chr(9) & _
    quantity & Chr(9) & _
    open_date & Chr(9) & _
    Image_url & Chr(9) & _
    product_id & Chr(9) & _
    product_id_type & Chr(9) & _
    zshop_shipping_fee & Chr(9) & _
    item_note & Chr(9) & _
    item_condition & Chr(9) & _
    zshop_category1 & Chr(9) & _
    zshop_browse_path & Chr(9) & _
    zshop_storefront_feature & Chr(9) & _
    Asin1 & Chr(9) & _
    Asin2 & Chr(9) & _
    Asin3 & Chr(9) & _
    will_ship_internationally & Chr(9) & _
    zshop_boldface & Chr(9) & _
    product_id & Chr(9) & _
    bid_for_featured_placement & Chr(9) & _
    add_delete & Chr(9) & _
    pending_quantity

    Your program concatenated most of the lines into a single unreadable line, but left some of it on the next line, in red (meaning that it was formatted illegally).

    I haven't had time yet to look at the code to mend it, but it is certainly a problem as I have several such instances and the whole point of placing things on multiple lines was to make it more readable.

    Thank you.

    Chris.

  9. #9
    Junior Member
    Join Date
    Jul 2008
    Posts
    23

    Re: VBTools AddIn - Auto indent VB code !

    Ok ... I've found the solution - simply comment out the following line:


    ' AllCode = Replace$(AllCode, "_" & vbNewLine, "")


    Thank you ... a very useful tool ... I've got over 40,000 lines of code that are mostly indented properly but just needs tidying up in places.

    Chris.


    I'm new here and my original post seems to have disappeared ... so here is something similar:

    The add-in is excellent but multiple lines with continuation underscores are joined together on a single ... which leaves SOME of them left over, creating illegal code.

    The reason I need this is because I'm hard coding a tab-delimited file header (it will not change, honestly!). Here it is:

    HeaderString = "item-name" & Chr(9) & _
    "item-description" & Chr(9) & _
    "listing-id" & Chr(9) & _
    "seller-sku" & Chr(9) & _
    "price" & Chr(9) & _
    "quantity" & Chr(9) & _
    "open-date" & Chr(9) & _
    "image-url" & Chr(9) & _
    "item-is-marketplace" & Chr(9) & _
    "product-id-type" & Chr(9) & _
    "zshop-shipping-fee" & Chr(9) & _
    "item-note" & Chr(9) & _
    "item-condition" & Chr(9) & _
    "zshop-category1" & Chr(9) & _
    "zshop-browse-path" & Chr(9) & _
    "zshop-storefront-feature" & Chr(9) & _
    "asin1" & Chr(9) & _
    "asin2" & Chr(9) & _
    "asin3" & Chr(9) & _
    "will-ship-internationally" & Chr(9) & _
    "zshop-boldface" & Chr(9) & _
    "product-id" & Chr(9) & _
    "bid-for-featured-placement" & Chr(9) & _
    "add-delete" & Chr(9) & _
    "pending-quantity"

    When concatenated, it is too long for one line ... also is not readable. The whole purpose of using the underscore is to make the code more readable.

    Thank you again for the useful software.
    Last edited by Chrisikins; Jul 22nd, 2008 at 04:33 AM.

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: VBTools AddIn - Auto indent VB code !

    Welcome to VBForums

    Thanks for sharing your solution.
    Quote Originally Posted by Chrisikins
    I'm new here and my original post seems to have disappeared ...
    Sorry about that - our Spam protection decided it needed to be manually checked, and there wasn't anyone available to check it for a while.

    I've now approved it, and you should not have this problem again.

  11. #11
    Junior Member
    Join Date
    Jul 2008
    Posts
    23

    Re: VBTools AddIn - Auto indent VB code !

    Thank you, Si.

    This looks like a useful forum .... one that I've only just discovered, so I shall hang around and hopefully learn ... and possibly even contribute, although there are many better brains around than mine!

    Chris.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VBTools AddIn - Auto indent VB code !

    Hi Chrisikins,

    I am aware about the "bug"...

    I don't really consider it a bug because I did that intentionally (so that the rest of the code can work properly)

    I actually rarely use the underscore "_" when I make my programs, I just don't like it...

    In your case, you can write your code like this:
    Code:
    HeaderString = "item-name" & Chr(9)
    HeaderString = HeaderString & "item-description" & Chr(9)
    HeaderString = HeaderString & "listing-id" & Chr(9)
    HeaderString = HeaderString & "seller-sku" & Chr(9)
    ...
    I was planning to fix the "bug", but I always forgot about it, and I rarely have time latelly to look over the code to fix the problem.

    I don't understand why would it remove the "_" in only some cases... maybe if you post the code before and after change by my Add-In... maybe I can figure out why this happens...

  13. #13
    Junior Member
    Join Date
    Jul 2008
    Posts
    23

    Re: VBTools AddIn - Auto indent VB code !

    I've just realised that it was one of the other standard headers, this:

    OutString = Item_Name & Chr(9) & _
    Item_Description & Chr(9) & _
    listing_id & Chr(9) & _
    seller_sku & Chr(9) & _
    Price & Chr(9) & _
    quantity & Chr(9) & _
    open_date & Chr(9) & _
    Image_url & Chr(9) & _
    product_id & Chr(9) & _
    product_id_type & Chr(9) & _
    zshop_shipping_fee & Chr(9) & _
    item_note & Chr(9) & _
    item_condition & Chr(9) & _
    zshop_category1 & Chr(9) & _
    zshop_browse_path & Chr(9) & _
    zshop_storefront_feature & Chr(9) & _
    Asin1 & Chr(9) & _
    Asin2 & Chr(9) & _
    Asin3 & Chr(9) & _
    will_ship_internationally & Chr(9) & _
    zshop_boldface & Chr(9) & _
    product_id & Chr(9) & _
    bid_for_featured_placement & Chr(9) & _
    add_delete & Chr(9) & _
    pending_quantity


    .... here is the final set of lines that your program produced ... but each segment pair has 25 spaces between:

    OutString = Item_Name & Chr(9) & Item_Description & Chr(9) & listing_id & Chr(9) & seller_sku & Chr(9) & Price & Chr(9) & quantity & Chr(9) & open_date & Chr(9) & Image_url & Chr(9) & product_id & Chr(9) & product_id_type & Chr(9) & zshop_shipping_fee & Chr(9) & item_note & Chr(9) & item_condition & Chr(9) & zshop_category1 & Chr(9) & zshop_browse_path & Chr(9) & zshop_storefront_feature & Chr(9) & Asin1 & Chr(9) & Asin2 & Chr(9) & Asin3 & Chr(9) & will_ship_internationally & Chr(9) & zshop_boldface & Chr(9) &
    product_id & Chr(9) & bid_for_featured_placement & Chr(9) & add_delete & Chr(9) & pending_quantity


    Not so much a bug, as you say. I think the reason is the fact of the size and number of continuations.

    I also like to use continuations for complex CHOOSE statements and where I use long literals in MSGBOX statements. Yes, I KNOW I should be using RES files, etc., but it is often more convenient to use literals!

    Chris.

  14. #14
    Junior Member
    Join Date
    Jul 2008
    Posts
    23

    Re: VBTools AddIn - Auto indent VB code !

    Whoops ... sorry ... must have pressed the send button twice. Probably my Alzheimers kicking in .... unfortunately I don't seem to be able to delete it!

    c.

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: VBTools AddIn - Auto indent VB code !

    You certainly aren't the first to do that! You can't delete posts yourself, so I have deleted it for you.

  16. #16
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: VBTools AddIn - Auto indent VB code !

    Michael,

    I am creating a simple add-in for Access 2010 using VBA. I want to provide it to clients unencumbered. Some code I use comes from V-Tools, http://www.skrol29.com/us/vtools.php#support and skrol29 has agreed to license it under lgpl3.
    I have used some code from mdlIndent.bas and would like to know if it can also be used under this license.

    Thanks,

    Peter

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VBTools AddIn - Auto indent VB code !

    I don't know much about licenses (and I don't have time to read about this license right now), but if your asking for permission to use my code in your add-in, then "yes", you can use it. Just put a comment with a link to this thread in front of the code that you copied. That is enough for me...

    PS. Thanks for asking

  18. #18
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: VBTools AddIn - Auto indent VB code !

    Much appreciated! Link and credit now included.

    Thanks,

    Peter

  19. #19
    Frenzied Member
    Join Date
    May 2013
    Posts
    1,126

    Re: VBTools AddIn - Auto indent VB code !

    can we further request for the removal of excess blank lines?

  20. #20
    New Member
    Join Date
    Mar 2017
    Posts
    2

    Re: VBTools AddIn - Auto indent VB code !

    Hello, Michael.

    I used your code from mdlIndent.bas with several changes for writing simple add-in, which the written on Delphi language, for 32- and 64-bites host applications.
    I planing distribute compiled dll for free, include source code under MIT license.
    Can I share this code with mark about originals algorithm author and link to this tread?

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VBTools AddIn - Auto indent VB code !

    Quote Originally Posted by OseVoso View Post
    Hello, Michael.

    I used your code from mdlIndent.bas with several changes for writing simple add-in, which the written on Delphi language, for 32- and 64-bites host applications.
    I planing distribute compiled dll for free, include source code under MIT license.
    Can I share this code with mark about originals algorithm author and link to this tread?
    Sure, no problem, thanks for asking!

  22. #22
    New Member
    Join Date
    Mar 2017
    Posts
    2

    Re: VBTools AddIn - Auto indent VB code !

    Many thanks, Michael!

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