# Re: 请问RichTextBox..

Posted by 小瓜瓜 on August 16, 1999 at 02:00:36:

In Reply to: Re: 请问RichTextBox.. posted by 小琳 on August 07, 1999 at 17:20:35:

: : 请问在richtextbox中如何在第n行中
: : 的第几个字元开始插入文字呢?

: :::程式如下:
: Option Explicit

: Private Sub Command1_Click()
: Dim i As Integer, a As Integer, b As Integer
:
: i = 0
: a = 0
: b = 0
: i = InStr(1, RichTextBox1.Text, Chr(10))
: a = 1
: Do While a < Val(Text1)
: b = i
: i = InStr(i + 1, RichTextBox1.Text, Chr(10))
: a = a + 1
: Loop
:
RichTextBox1.Text = Left(RichTextBox1.Text, b) & Mid(RichTextBox1.Text, b + 1, Val(Text2)) & Trim(Text3.Text) & Mid(RichTextBox1.Text, b + Val(Text2) + 1)
: MsgBox RichTextBox1.Text
:
: End Sub

Dim R As Long '第几行
Dim P As Long '第几个字
Dim L As Long '嘿嘿
Dim MyStr As String '嘿嘿
Dim InsStr As String '要插入的字串

MyStr = RichTextBox1.Text

R = 4 '第四行
P = 10 '第十个字
InsStr = "Hello!" '插入"Hello!"

For N = 2 To R
P = InStr(MyStr, Chr(10))
L = L + P + 2
MyStr = Right(MyStr, Len(MyStr) - P)
MsgBox MyStr & ":" & L
If P = 0 Then Exit For
Next

L = L + R
RichTextBox1.SelStart = L
RichTextBox1.SelText = InsStr

- 小瓜瓜VB调理包

Follow Ups: