Results 1 to 6 of 6

Thread: Replicating Vb's Comment Code!?!?!

  1. #1
    Guest

    Lightbulb

    Im trying to replicate the way Visual Basic does its commenting when you click on the comment button in the editing toolbar it will comment all the lines you have selected or the line you have selected..But I cant figure out how to get it to put the ' character as the first character in all the lines..Does anyone know how to do this?

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Try adding this (Syntax may need work, its off the top of my head)

    Code:
    RichTextBox.SelText = Replace(RichTextBox.SelText,vbCR,vbCR & "'")
    You might need to change vbCR to vbCRLF and you might need to pass all but the last character of the .SelText so it doesn't put a ' on the line after your selection.

  3. #3
    Guest
    I tried this and it worked ok but if you highlight the text using your mouse going from bottom to top.. it misses the last line of code becuase you dont hightlight the line character feeds at the end of the line...to the user this wont make since because that line is highlighted..

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Selecting the entire text and only using all but 1 single character of the last line should still make the last line be commented out.

    The reason for this is that the comment FOLLOWS the Carriage Return and regardless whether the last line ends in a Carriage Return or just ends it will do it because the one before is the reason THIS line gets it.

    Paste the code in here and I will see where you have missed it

  5. #5
    Guest

    Code:
    Dim Buffer As Variant
    
    Dim i As Integer
    If txtMain.SelLength = 0 Then
    txtMain.SelText = "#"
    Else
    Buffer = txtMain.SelText
    txtMain.SelText = Replace(Buffer, vbCr, vbCr & "'")
    End If

    Returns this

    d
    '
    fafdjfkldsjf;lkdjfkdljdsf
    '
    fsd
    '
    d
    '
    d
    '

  6. #6
    Guest
    yeah it was vblf.. thanks man...

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