|
-
Oct 18th, 2002, 11:04 AM
#1
Thread Starter
Frenzied Member
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?
-
Oct 18th, 2002, 11:44 AM
#2
PowerPoster
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.
-
Oct 18th, 2002, 02:39 PM
#3
Addicted Member
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.
-
Oct 18th, 2002, 02:54 PM
#4
PowerPoster
Do you have code to get the line number?
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, lParam As Any) As Long
Public Function GetLineFromChar(CharPos As Long) As Long
'Returns the zero based line number of the line
'that contains the specified character index
GetLineFromChar = SendMessage(txtCodeFile.hwnd, EM_LINEFROMCHAR, CharPos, 0&)
End Function
'call the above function like this:
'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.
-
Oct 19th, 2002, 03:51 AM
#5
Thread Starter
Frenzied Member
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!
-
Oct 19th, 2002, 04:03 AM
#6
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
-
Oct 19th, 2002, 04:09 AM
#7
Thread Starter
Frenzied Member
THis is what im trying to say...i dont know the symbol for shift in
SendKeys.
-
Oct 19th, 2002, 04:13 AM
#8
Heres Some Code
//See Attached Textfile for clsKeys
VB Code:
'note ur gonna have to set the focus the the line in the rtb
Dim clsKeys as clsKeys
Set clskeys = new clsKeys
Dim I as Integer
PressKeyVK keyShift, True
Do Until I = Len(Line)
PressKeyVK keyRight
I = I + 1
Loop
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
-
Oct 19th, 2002, 05:09 AM
#9
Thread Starter
Frenzied Member
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:
Public Sub SelLine(RTB As RichTextBox)
Dim x As Long, i As Integer
Dim y As String, z As String, a As String
y = 0
a = 0
z = 0
Dim bolBegin As Boolean, bolEnd As Boolean
x = RTB.GetLineFromChar(RTB.SelStart)
i = RTB.SelStart
'a = RtB.GetLineFromChar(i)
If RTB.GetLineFromChar(i) = 0 Then
bolBegin = True
y = 1
End If
If RTB.GetLineFromChar(i) = UBound(Split(RTB.Text, vbNewLine)) Then
bolEnd = True
z = Len(RTB.Text)
End If
Do Until RTB.GetLineFromChar(i) = x - 1 Or bolBegin = True
i = i - 1
Loop
i = i + 1
y = 0
If Not bolBegin Then y = i
i = RTB.SelStart
Do Until RTB.GetLineFromChar(i) = x + 1 Or bolEnd = True
i = i + 1
Loop
z = Len(RTB.Text) + 1
If Not bolEnd Then z = i
z = z - y
RTB.SelStart = y
RTB.SelLength = z
RTB.SetFocus
End Sub
-
Oct 28th, 2002, 04:02 AM
#10
Fanatic Member
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
-
Oct 28th, 2002, 04:34 AM
#11
So Unbanned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|