From: herb on
i've a richtextbox in which it is possible to make entries.

due to the tabulator is not working inside the rtb (it always jumps to
the next TabIndex element), and it is not possible like in a "normal"
textbox to enable/disable the tab, i want to implement following
solution:

1. get the actual position (row,col) of the cursor in the rtb
2. add 10 blanks in the given (row,col)

the first one (getting the acutual position) is already working with:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam
As Long) As Long
Private Const EM_LINEINDEX = &HBB

Private Sub Text1_Change
Dim nLine&
Dim nLineStart&
Dim ActualRow
Dim ActualCol

nLine& = Text1.GetLineFromChar(Text1.SelStart)
nLineStart& = SendMessage(Text1.hwnd, EM_LINEINDEX, -1, 0)

ActualRow = Format$(nLine& + 1, "0")
ActualCol = Format$(Text1.SelStart + Text1.SelLength - nLineStart& +
1, "0"

but for the second task.....
using rtb.find or rtb.setfocus wasn't successful....


thanks in advance,
herb


note: i'm using a "limited" version of vb6.3 (like vba)

From: Rick Rothstein [MVP - Visual Basic] on
> the first one (getting the acutual position) is already working with:
>
> Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
> (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
> lParam
> As Long) As Long
> Private Const EM_LINEINDEX = &HBB
>
> Private Sub Text1_Change
> Dim nLine&
> Dim nLineStart&
> Dim ActualRow
> Dim ActualCol
>
> nLine& = Text1.GetLineFromChar(Text1.SelStart)
> nLineStart& = SendMessage(Text1.hwnd, EM_LINEINDEX, -1, 0)
>
> ActualRow = Format$(nLine& + 1, "0")
> ActualCol = Format$(Text1.SelStart + Text1.SelLength - nLineStart& +
> 1, "0"

You can get both the Column and Row using API calls. The following is from a
previous post of mine.

Rick - MVP

The following, written for a normal TextBox, will also works with a
RichTextBox if the references are changed appropriately (TextBox to
RichTextBox).

Paste this code in the (General)(Declarations) section of your Form for
single form use; or place it into a BAS Module (Project/AddModule from VB
menu bar) for project wide scope:

Private Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB

Function CursorLine(TextBoxIn As TextBox) As Long
CursorLine = SendMessageLong(TextBoxIn.hwnd, _
EM_LINEFROMCHAR, -1, 0) + 1
End Function

Function CursorColumn(TextBoxIn As TextBox) As Integer
CursorColumn = TextBoxIn.SelStart - SendMessageLong( _
TextBoxIn.hwnd, EM_LINEINDEX, -1, 0)
End Function

The CursorLine function returns the line number counting the first line as
Line #1 (that is what the +1 does; remove it to count from zero). The
CursorColumn function returns the number of characters that exist to the
left of the cursor. Simply pass the TextBox in as an argument to either
function; for example

Private Sub Text1_Click()
MsgBox "The cursor is on Line #" & CursorLine(Text1) & _
" at Column #" & CursorColumn(Text1)
End Sub


From: Rick Rothstein [MVP - Visual Basic] on
> due to the tabulator is not working inside the rtb (it always jumps to
> the next TabIndex element), and it is not possible like in a "normal"
> textbox to enable/disable the tab, i want to implement following
> solution:
>
> 1. get the actual position (row,col) of the cursor in the rtb
> 2. add 10 blanks in the given (row,col)
>
> but for the second task.....
> using rtb.find or rtb.setfocus wasn't successful....

I'm not entirely clear on what you want to do here. Are you trying to insert
10 blank spaces at the cursor's current location? If so, just do this...

rtb.SelText = Space$(10)

If this is not what you want, can you explain what you want in a little more
detail?

Rick


From: herb on
first of all thanks for your reply

i didn't know that this is so easy to handle....

thanks a lot!!


i don't know if you can remember the one topic with "search csv in
first column -> return value from second column same row"

this function is working well, but is it possible to search for a
subset-string?

i.e.:
- in first column the string "12test34" exists
- searchstring "test"
- returns the value from the row where "12test34" is positioned
- first matching is sufficient

i tried to modify your "original" function without success....


thanks in advance,
herb

From: herb on
finally i was successfully.... modifying the instr() function with
InStrLikeRev()....

 | 
Pages: 1
Prev: Reading USB port
Next: Run-time error 429