-
Jul 12th, 2022, 06:14 PM
#1
Thread Starter
Member
Vb6: richtextbox read line by line on click
i need to read all lines from richtextbox to text1.text when i click command1 one by one
i have used this code, it works for msgbox, but for text1.txt not working, plz help
Private Sub Command1_Click()
Dim arr() As String
Dim i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
For i = 0 To UBound(arr)
Text1.Text = arr(i)
Next
End Sub
Last edited by vb6s; Jul 12th, 2022 at 06:20 PM.
-
Jul 12th, 2022, 06:51 PM
#2
Re: Vb6: richtextbox read line by line on click
Waht do you mean by "not working" that's pretty vague.
It probably is working... it's doing exactly what you told it to do. But it's not what you want it to do.
When you do this: Text1.Text = arr(i) ... you're replacing the text each tiem thtrough... so only the last line ges displayed. Try adding or concatenating the text box text rther than overwriting it. But then if that's what you want, why not just set the textbox.text = richtextbox.text ...
-tg
-
Jul 12th, 2022, 07:03 PM
#3
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by techgnome
Waht do you mean by "not working" that's pretty vague.
It probably is working... it's doing exactly what you told it to do. But it's not what you want it to do.
When you do this: Text1.Text = arr(i) ... you're replacing the text each tiem thtrough... so only the last line ges displayed. Try adding or concatenating the text box text rther than overwriting it. But then if that's what you want, why not just set the textbox.text = richtextbox.text ...
-tg
because this is actual project;
i have two multiline richboxes,
richtextbox1:
david qwefasdfds jones
tonys xzcxz rockfeler
adams wxvefwefewcx diny
richtextbox2:
david
tonys
i need to extract this to richtextbox3.text: only richtextbox1 lines that are duplicate in richtextbox2
so result in richtextbox3.text would be:
david qwefasdfds jones
tonys xzcxz rockfeler
Last edited by vb6s; Jul 12th, 2022 at 07:36 PM.
-
Jul 12th, 2022, 10:02 PM
#4
Re: Vb6: richtextbox read line by line on click
Originally Posted by vb6s
i need to read all lines from richtextbox to text1.text when i click command1 one by one
i have used this code, it works for msgbox, but for text1.txt not working, plz help
Private Sub Command1_Click()
Dim arr() As String
Dim i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
For i = 0 To UBound(arr)
Text1.Text = arr(i)
Next
End Sub
Code:
Private Sub Command1_Click()
Dim arr() As String
Dim i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
For i = 0 To UBound(arr)
Text1.SelText = arr(i)
Next
End Sub
-
Jul 13th, 2022, 04:32 AM
#5
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by Eduardo-
Code:
Private Sub Command1_Click()
Dim arr() As String
Dim i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
For i = 0 To UBound(arr)
Text1.SelText = arr(i)
Next
End Sub
this is get all lines together to text1
i need to get lines one by one on each click
-
Jul 13th, 2022, 05:07 AM
#6
Re: Vb6: richtextbox read line by line on click
You have to explain in more detail what you want to achieve.
Do you want a multiline textbox in which all content of the RTB is copied when Command1 is clicked?
Do you want a single line textbox in which only the line selected in the RTB is copied?
-
Jul 13th, 2022, 05:50 AM
#7
Lively Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by vb6s
i need to read all lines from richtextbox to text1.text when i click command1 one by one
i have used this code, it works for msgbox, but for text1.txt not working, plz help
Private Sub Command1_Click()
Dim arr() As String
Dim i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
For i = 0 To UBound(arr)
Text1.Text = arr(i)
Next
End Sub
When you say "i have used this code, it works for msgbox", can you please share the working code too. It might help in working out the source of the problem.
-
Jul 13th, 2022, 05:56 AM
#8
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by Dan_W
When you say "i have used this code, it works for msgbox", can you please share the working code too. It might help in working out the source of the problem.
Dim arr() As String
Dim i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
For i = 0 To UBound(arr)
Text1.Text = arr(i)
Next
-
Jul 13th, 2022, 05:56 AM
#9
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by Arnoutdv
You have to explain in more detail what you want to achieve.
Do you want a multiline textbox in which all content of the RTB is copied when Command1 is clicked?
Do you want a single line textbox in which only the line selected in the RTB is copied?
i have two multiline richboxes,
richtextbox1:
david qwefasdfds jones
tonys xzcxz rockfeler
adams wxvefwefewcx diny
richtextbox2:
david
tonys
i need to extract this to richtextbox3.text: only richtextbox1 lines that are duplicate in richtextbox2
so result in richtextbox3.text would be:
david qwefasdfds jones
tonys xzcxz rockfeler
-
Jul 13th, 2022, 06:12 AM
#10
Re: Vb6: richtextbox read line by line on click
The general approach could be:
store the content of RTB1 in a string array1
store the content of RTB2 in a string array2
Code:
For each line in string array2
Get the word from array2
Loop thru all items for array1
Get the first word of the current item of array1
If the word from array1 matches the word from array2 add it to RTB3
-
Jul 13th, 2022, 06:44 AM
#11
Re: Vb6: richtextbox read line by line on click
Originally Posted by vb6s
this is get all lines together to text1
i need to get lines one by one on each click
OK.
Code:
Private Sub Command1_Click()
Dim arr() As String
Static i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
If i > UBound(arr) Then i = 0
Text1.Text = arr(i)
i = i + 1
End Sub
-
Jul 13th, 2022, 08:45 AM
#12
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by Eduardo-
OK.
Code:
Private Sub Command1_Click()
Dim arr() As String
Static i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
If i > UBound(arr) Then i = 0
Text1.Text = arr(i)
i = i + 1
End Sub
it works but i still have other problem
-
Jul 13th, 2022, 08:46 AM
#13
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by Arnoutdv
The general approach could be:
store the content of RTB1 in a string array1
store the content of RTB2 in a string array2
Code:
For each line in string array2
Get the word from array2
Loop thru all items for array1
Get the first word of the current item of array1
If the word from array1 matches the word from array2 add it to RTB3
here my code. plz help me improve it, bcoz i works with 100-1000 lines maximum then it stops
Code:
Private Sub Command1_Click()
On Error Resume Next
Dim arr() As String
Static i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
If i > UBound(arr) Then i = 0
Text3.Text = arr(i)
i = i + 1
Text4.Text = Left(Text3.Text, 5)
Text4.Text = Replace(Text4.Text, "|", "")
If InStr(RichTextBox2.Text, Text4.Text) Then
RichTextBox3.Text = RichTextBox3.Text & vbNewLine & Text3.Text
End If
Dim LastLine() As String
LastLine = Split(RichTextBox1.Text, vbCrLf)
Text6.Text = LastLine(UBound(LastLine))
If InStr(Text3.Text, Text6.Text) Then
Command1.Enabled = False
End If
If Command1.Enabled = True Then
Call Command1_Click
End If
End Sub
Last edited by vb6s; Jul 13th, 2022 at 08:54 AM.
-
Jul 13th, 2022, 08:49 AM
#14
Re: Vb6: richtextbox read line by line on click
Please enclose the code between code tags, it is very hard to read unformatted code.
Select the code, and click on # on the toolbar
-
Jul 13th, 2022, 08:57 AM
#15
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
i have two multiline richboxes,
richtextbox1:
david|qwefasdfds jones
tonys|xzcxz rockfeler
adams|wxvefwefewcx diny
richtextbox2:
david
tonys
i need to extract this to richtextbox3.text: only richtextbox1 lines that are duplicate in richtextbox2
so result in richtextbox3.text would be:
david qwefasdfds jones
tonys xzcxz rockfeler
here my code. but it work only with 100-1000 lines
Code:
Private Sub Command1_Click()
On Error Resume Next
Dim arr() As String
Static i As Integer
arr = Split(RichTextBox1.Text, vbCrLf)
If i > UBound(arr) Then i = 0
Text3.Text = arr(i)
i = i + 1
Text4.Text = Left(Text3.Text, 5)
Text4.Text = Replace(Text4.Text, "|", "")
If InStr(RichTextBox2.Text, Text4.Text) Then
RichTextBox3.Text = RichTextBox3.Text & vbNewLine & Text3.Text
End If
Dim LastLine() As String
LastLine = Split(RichTextBox1.Text, vbCrLf)
Text6.Text = LastLine(UBound(LastLine))
If InStr(Text3.Text, Text6.Text) Then
Command1.Enabled = False
End If
If Command1.Enabled = True Then
Call Command1_Click
End If
End Sub
-
Jul 15th, 2022, 07:06 AM
#16
Thread Starter
Member
Re: Vb6: richtextbox read line by line on click
i already posted code 2 days ago but still no one help
-
Jul 15th, 2022, 09:47 AM
#17
Member
Re: Vb6: richtextbox read line by line on click
hello, hope it helps you
All lines
Line by line
happy pr0gramm1ng lines
Last edited by sah1d; Jul 15th, 2022 at 10:18 AM.
-
Jul 15th, 2022, 10:47 AM
#18
Re: Vb6: richtextbox read line by line on click
Originally Posted by vb6s
i already posted code 2 days ago but still no one help
Perhaps open a new thread and explain your problem with clarity, it is not clear what you want and what is not working.
-
Jul 15th, 2022, 11:20 AM
#19
Member
Re: Vb6: richtextbox read line by line on click
Originally Posted by Eduardo-
Perhaps open a new thread and explain your problem with clarity, it is not clear what you want and what is not working.
Maybe it's the only explanation they gave him at school
-
Jul 15th, 2022, 02:14 PM
#20
Re: Vb6: richtextbox read line by line on click
WOW----just read this thread...HOW CONFUSING!
Sam I am (as well as Confused at times).
-
Jul 15th, 2022, 02:46 PM
#21
Re: Vb6: richtextbox read line by line on click
RE: #15
Not sure if this is what THAT Post is trying to do, but I THINK it is like this easy example (I used two listboxes, but you could use arrays).
Whole program is three richtextboxes, two listboxes, and one commandbutton:
Code:
Option Explicit
Private Sub Form_Load()
RichTextBox1.Text = "david qwefasdfds jones" & vbCrLf & "tonys xzcxz rockfeler" & vbCrLf & "adams wxvefwefewcx diny"
RichTextBox2.Text = "david" & vbCrLf & "tonys"
End Sub
Private Sub Command1_Click()
Dim i As Long, j As Long
Dim array1() As String, array2() As String, array3() As String
array1 = Split(RichTextBox1.Text, vbCrLf)
Dim lName As String
For i = 0 To UBound(array1)
j = InStr(1, array1(i), " ")
lName = Mid(array1(i), 1, j - 1)
List1.AddItem (lName)
Next i
array3 = Split(RichTextBox2.Text, vbCrLf)
For i = 0 To UBound(array3)
List2.AddItem (array3(i))
Next i
For i = List1.ListCount - 1 To 0 Step -1
For j = 0 To List1.ListCount - 1
If List1.List(i) = List2.List(j) Then
RichTextBox3.Text = RichTextBox3.Text & (array1(j)) & vbCrLf
End If
Next
Next
End Sub
Sam I am (as well as Confused at times).
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
|