Results 1 to 11 of 11

Thread: Select a Line in a RTB

  1. #1

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Select a Line in a RTB

    Hello! All i want to know is, how can i select a SPECIFIC line? The
    whole line! I mean, all i have to do is run an index number
    through it and it will select that line!

    Lets say if i want line 2 selected...the second line in that RTB will
    become selected.... make sense? Can anybody help me?
    Luke

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    you'll have to search for vbCrLf and capture the stuff between number n-1 and number n.

    look on planetsourcecode and see if somebody's already done it.

  3. #3
    Addicted Member
    Join Date
    Nov 2001
    Posts
    153

    SendKeys???

    I know a lot of people don't like it but you could try sendkeys home, then shift and end, I cant remeber the special codes for ctrl, shift, alt etc, sorry, look them up in help.

  4. #4
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Do you have code to get the line number?

    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    2. Long, ByVal wParam As Long, lParam As Any) As Long
    3.  
    4. Public Function GetLineFromChar(CharPos As Long) As Long
    5. 'Returns the zero based line number of the line
    6. 'that contains the specified character index
    7.     GetLineFromChar = SendMessage(txtCodeFile.hwnd, EM_LINEFROMCHAR, CharPos, 0&)
    8. End Function
    9. 'call the above function like this:
    10. 'MsgBox GetLineFromChar(RichTextBox1.SelStart)

    and once you have the cursor in that line, just use InstrRev to find the last vbCrLf from the position of the cursor, then use InStr to find the next vbCrLf from the position of the cursor, then use Mid to get the data between those two positions.

    I've gotta go to work right now, but I'll try to write some code to do it when I get there.
    <removed by admin>

  5. #5

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    I dont want to get the line number, I want to SELECT the line in
    the RTB! As for SendKeys...just give me the key combination
    string and ill try!
    Luke

  6. #6
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Hold Shift And Press --> as Many Times as the Line is Long
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  7. #7

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    THis is what im trying to say...i dont know the symbol for shift in
    SendKeys.
    Luke

  8. #8
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Heres Some Code

    //See Attached Textfile for clsKeys

    VB Code:
    1. 'note ur gonna have to set the focus the the line in the rtb
    2.  
    3. Dim clsKeys as clsKeys
    4. Set clskeys = new clsKeys
    5. Dim I as Integer
    6.  
    7. PressKeyVK keyShift, True
    8.  
    9. Do Until I = Len(Line)
    10.      PressKeyVK keyRight
    11.      I = I + 1
    12. Loop
    13.  
    14. PressKeyVK vkShift, False, True
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  9. #9

    Thread Starter
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    I got it! I wrote a sub routine that will select the line that the cursor is on in the given RTB...heres the code if anyone's interested:
    VB Code:
    1. Public Sub SelLine(RTB As RichTextBox)
    2.  Dim x As Long, i As Integer
    3.  Dim y As String, z As String, a As String
    4.  y = 0
    5.  a = 0
    6.  z = 0
    7.  Dim bolBegin As Boolean, bolEnd As Boolean
    8.  x = RTB.GetLineFromChar(RTB.SelStart)
    9.  i = RTB.SelStart
    10.  
    11.  'a = RtB.GetLineFromChar(i)
    12.  If RTB.GetLineFromChar(i) = 0 Then
    13.   bolBegin = True
    14.   y = 1
    15.  End If
    16.  If RTB.GetLineFromChar(i) = UBound(Split(RTB.Text, vbNewLine)) Then
    17.   bolEnd = True
    18.   z = Len(RTB.Text)
    19.  End If
    20.  Do Until RTB.GetLineFromChar(i) = x - 1 Or bolBegin = True
    21.   i = i - 1
    22.  Loop
    23.  i = i + 1
    24.  y = 0
    25.  If Not bolBegin Then y = i
    26.  i = RTB.SelStart
    27.  Do Until RTB.GetLineFromChar(i) = x + 1 Or bolEnd = True
    28.   i = i + 1
    29.  Loop
    30.  z = Len(RTB.Text) + 1
    31.  If Not bolEnd Then z = i
    32.  z = z - y
    33.  RTB.SelStart = y
    34.  RTB.SelLength = z
    35.  RTB.SetFocus
    36. End Sub
    Luke

  10. #10
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589

    I can tell you a much simpler one

    dim LineStart() as long
    'After the textbox is loaded, CALL THIS FUNCTION
    private sub LoadLineNumbers()
    dim temp as long
    dim curInd as long
    rtbbox.SelStart=0
    do while curInd<=len(rtbbox.text)
    redim Preserve LineStart(0 to temp)
    LineStart(temp)=curInd
    rtbbox.Upto chr(13)+chr(10),true,false
    rtbbox.selstart=rtbbox.selstart+2
    curInd=rtbbox.selStart
    temp=temp+1
    loop

    end sub
    'If you execute this routine you'll have all the line start positions in the array
    'Now if you want to get a particular line into a sstring just call this function with line 'number

    private function GetTheLine (lineNo as long) as string
    if lineNo>UBound(LineStart)+1 or lineNo<=LBound(LineStart) then
    dim temp as long
    rtbbox.selstart=LineStart(lineNo-1)
    rtbbox.Upto chr(13)+chr(10),true,false
    temp=rtbbox.selstart
    rtbbox.selstart=LineStart(lineNo-1)
    rtbbox.selLength=temp-rtbbox.selstart
    GetTheLine=rtbbox.seltext
    rtbbox.sellength=0
    else
    msgbox "Error in accessing the line number",vbCritical
    end if

    end function

  11. #11
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    On vb-world.net there is a sample program which does this and more.

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