Results 1 to 21 of 21

Thread: Vb6: richtextbox read line by line on click

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    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.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by techgnome View Post
    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.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by vb6s View Post
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by Eduardo- View Post
    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

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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?

  7. #7
    Lively Member
    Join Date
    May 2021
    Posts
    95

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by vb6s View Post
    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.

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by Dan_W View Post
    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

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by Arnoutdv View Post
    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

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    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

  11. #11
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by vb6s View Post
    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

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by Eduardo- View Post
    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

  13. #13

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by Arnoutdv View Post
    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.

  14. #14
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    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

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    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

  16. #16

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: richtextbox read line by line on click

    i already posted code 2 days ago but still no one help

  17. #17
    Member
    Join Date
    Jun 2022
    Posts
    40

    Re: Vb6: richtextbox read line by line on click

    hello, hope it helps you

    All lines
    Code:
    null
    Line by line
    Code:
    null
    happy pr0gramm1ng lines
    Last edited by sah1d; Jul 15th, 2022 at 10:18 AM.

  18. #18
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,997

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by vb6s View Post
    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.

  19. #19
    Member
    Join Date
    Jun 2022
    Posts
    40

    Re: Vb6: richtextbox read line by line on click

    Quote Originally Posted by Eduardo- View Post
    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

  20. #20
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    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).

  21. #21
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    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
  •  



Click Here to Expand Forum to Full Width