Results 1 to 11 of 11

Thread: [RESOLVED] vs2022, how to comment large blocks of code?. entire subs at once

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    874

    Resolved [RESOLVED] vs2022, how to comment large blocks of code?. entire subs at once

    I have 2 subs, like to just comment all without individually putting single quote on each line

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,684

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    Probably with #IF but I have never tried it.

    https://stackoverflow.com/questions/...ment-in-vb-net
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,663

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    Try selecting the code then press Ctrl-/ (hold the Ctrl key and press /) ... most IDEs use that for block (un)commenting... I know VSCode does it, so I assume Visual Studio will do the same.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Lively Member
    Join Date
    Jun 2023
    Posts
    79

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    In VS2022 select View > Toolbars > Text Editor.

    This toolbar has a comment and uncomment button on it. You can highlight as much of your code as you want and then press the comment button and it will comment it all out at once, and vice versa for uncomment.

    If you'd rather use keyboard shortcuts then it is CTRL+K Then CTRL+C to comment out your selected code, and CTRL+K Then CTRL+U to uncomment. You can press K then C or U while holding down control.

    Name:  text_editor.png
Views: 174
Size:  2.2 KB

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    874

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    Thanks, CTRL+K Then CTRL+C worked

    First highlight text then do that.

    Useful to me when developing subs, to make changes but keep the old working code just in case.
    Then also, I like to keep some code in comments in modules as examples of how to do things.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,326

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    I use the buttons that themindgoblin showed. The shortcut keys are also pretty nice, but Ctrl+C is always a bit risky, because that's Copy. You aren't as likely to make a mistake with that as you are with Ctrl+P or Ctrl+X, but re-use of Ctrl+ in this fashion can be awkward if you care also copying and pasting.
    My usual boring signature: Nothing

  7. #7
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    381

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    Quote Originally Posted by sdowney1 View Post
    Thanks, CTRL+K Then CTRL+C worked.
    Note 1) Remember to uncomment the highlighted section by Ctrl + K then Ctrl + U.
    Note 2) Layering comments by re-pressing shortcuts, helps priorized uncommenting and code engaging for dev purposes.
    Note 3) Remember to close the thread once you get a proper answer.
    peace/.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,658

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    You can collapse a sub, like so...

    Name:  17-07-2024 18.32.49.jpg
Views: 146
Size:  12.0 KB

    Name:  17-07-2024 18.33.14.jpg
Views: 157
Size:  4.5 KB

    Then highlight the entire collapsed code stub, and click the comment button on your toolbar. There's also an uncomment button that you can use to uncomment a sub or a block of commented code...

    Name:  17-07-2024 18.34.16.jpg
Views: 151
Size:  20.9 KB

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2024
    Posts
    874

    Re: vs2022, how to comment large blocks of code?. entire subs at once

    Thanks, all very helpful.

  10. #10
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,684

    Re: [RESOLVED] vs2022, how to comment large blocks of code?. entire subs at once

    So.

    Code:
            Dim i As Integer
            Dim x As Integer
    
            x = 123
    
    #If 0 Then
          
            i = 2
    
          
            x = 5
    #End If
    
            x = 4
            i = 3
    I'm testing this and it works better, you don't need to select oceans of code and quote them. Of course makes no sense for a line or two but for more it looks even better than C# /*

    Unfortunately I'm more on C# at the company now so that is a really late find, still it simulates a region of commend out code better than quoting everything, you just have to get used to it.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,658

    Re: [RESOLVED] vs2022, how to comment large blocks of code?. entire subs at once

    They’re called Preprocessing Directives…

    https://learn.microsoft.com/en-us/do...ing-directives

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