Results 1 to 17 of 17

Thread: Vb6: read richtextbox line by line; out of string space

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Vb6: read richtextbox line by line; out of string space

    i manually add to richtextbox1 over 5k in lines, and my goal is to read each line from richtextbox to text1
    then move to next and remove previous line
    however im gettting out of string space 14
    here my code, plz try it with +5k in lines and u will get same exact errror
    help me plzz

    Code:
    Private Sub Command1_Click()
    Dim arrLines() As String
    arrLines = Split(RichTextBox1.Text, vbCrLf)
    Text1.Text = arrLines(0)
    
    RichTextBox1.Text = Mid$(RichTextBox1.Text, InStr(1, RichTextBox1.Text, vbCrLf) + 2)
    Call Command1_Click
    
    End Sub

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,387

    Re: Vb6: read richtextbox line by line; out of string space

    you're calling the click event of Command1 IN Command1's click event????? You don't see an issue with that???
    Sam I am (as well as Confused at times).

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: read richtextbox line by line; out of string space

    Quote Originally Posted by SamOscarBrown View Post
    you're calling the click event of Command1 IN Command1's click event????? You don't see an issue with that???
    it is what i need to do
    it has to run this code with all lines in richtextbox

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,671

    Re: Vb6: read richtextbox line by line; out of string space


  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,082

    Re: Vb6: read richtextbox line by line; out of string space

    Quote Originally Posted by vb6s View Post
    it is what i need to do
    it has to run this code with all lines in richtextbox
    You need to do it, why?

    What you are doing in code now is completely nonsensical for multiple reasons. Give a small example of:

    1. The contents of RichTextBox1 before Command1 is clicked
    2. The contents of Text1 before Command1 is clicked
    3. The desired contents of RichTextBox1 after Command1 is clicked once
    4. The desired contents of Text1 after Command1 is clicked once

    That might help clear up what your goal is.

    Good luck.

  6. #6
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,430

    Re: Vb6: read richtextbox line by line; out of string space

    Quote Originally Posted by SamOscarBrown View Post
    you're calling the click event of Command1 IN Command1's click event????? You don't see an issue with that???
    He sees issues, but doesn't connect them.

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: read richtextbox line by line; out of string space

    Quote Originally Posted by OptionBase1 View Post
    You need to do it, why?

    What you are doing in code now is completely nonsensical for multiple reasons. Give a small example of:

    1. The contents of RichTextBox1 before Command1 is clicked
    2. The contents of Text1 before Command1 is clicked
    3. The desired contents of RichTextBox1 after Command1 is clicked once
    4. The desired contents of Text1 after Command1 is clicked once

    That might help clear up what your goal is.

    Good luck.
    Code:
    If RichTextBox1.Text = "" = False Then
    Call Command1_Click
    End If
    still showed me run time error 7 out of memory

  8. #8
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,951

    Re: Vb6: read richtextbox line by line; out of string space

    vb6s its the same issue and exactly the same solution for both the old and new thread.
    I gave u a solution. very simple and it should work here as well. DO NOT SPLIT. theres no need for that.

    Code:
    Private Sub Command1_Click()
    Dim Find&
    Static Pos&
    Find = InStr(Pos + 1, Text1.Text, vbCrLf)
    If Find > 0 Then
        Text2.Text = Mid$(Text1.Text, Pos + 1, Find - Pos - 1)
        Pos = Find + 1
    End If
    End Sub
    in this example (like before) u can replace text1.text with RichTextBox1.Text and it will work the same.
    it will start from first line and each time u click command it will take the next.
    this is just a sample, u need to adjust it for your needs.

    if u need to "remove" the first line from RichTextBox1 its even easier

    Code:
    Private Sub Command2_Click()
    Dim Find&
        Find = InStr(Text1.Text, vbCrLf)
        If Find > 0 Then
            Text2.Text = Left$(Text1.Text, Find - 1)
            Text1.Text = Right$(Text1.Text, Len(Text1.Text) - Find)
        End If
    End Sub
    again, replace with RichTextBox1.Text
    Last edited by baka; Aug 13th, 2022 at 02:10 AM.

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: read richtextbox line by line; out of string space

    Quote Originally Posted by baka View Post
    vb6s its the same issue and exactly the same solution for both the old and new thread.
    I gave u a solution. very simple and it should work here as well. DO NOT SPLIT. theres no need for that.

    Code:
    Private Sub Command1_Click()
    Dim Find&
    Static Pos&
    Find = InStr(Pos + 1, Text1.Text, vbCrLf)
    If Find > 0 Then
        Text2.Text = Mid$(Text1.Text, Pos + 1, Find - Pos - 1)
        Pos = Find + 1
    End If
    End Sub
    in this example (like before) u can replace text1.text with RichTextBox1.Text and it will work the same.
    it will start from first line and each time u click command it will take the next.
    this is just a sample, u need to adjust it for your needs.

    if u need to "remove" the first line from RichTextBox1 its even easier

    Code:
    Private Sub Command2_Click()
    Dim Find&
        Find = InStr(Text1.Text, vbCrLf)
        If Find > 0 Then
            Text2.Text = Left$(Text1.Text, Find - 1)
            Text1.Text = Right$(Text1.Text, Len(Text1.Text) - Find)
        End If
    End Sub
    again, replace with RichTextBox1.Text
    how is it possible to run it until richtextbox becomes emtpy ?

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2021
    Posts
    54

    Re: Vb6: read richtextbox line by line; out of string space

    something like this but i get error out of string space

    Dim arrLines() As String
    arrLines = Split(RichTextBox1.Text, vbCrLf)
    Text1.Text = arrLines(0)


    RichTextBox1.Text = Mid$(RichTextBox1.Text, InStr(1, RichTextBox1.Text, vbCrLf) + 2)
    Do While RichTextBox1.Text = "" = False
    Call Command1_Click
    Loop

    i wana keep running command till richtextbox becomes empty
    Last edited by vb6s; Aug 13th, 2022 at 05:46 AM.

  11. #11
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,951

    Re: Vb6: read richtextbox line by line; out of string space

    Code:
    Private Sub Command1_Click()
    Dim Find&
        Find = InStr(RichTextBox1.Text, vbCrLf)
        If Find > 0 Then
            Text1.Text = Left$(RichTextBox1.Text, Find - 1)
            RichTextBox1.Text = Right$(RichTextBox1.Text, Len(RichTextBox1.Text) - Find)
            Call Command1_Click() 
        else
            MsgBox "Its Done"    
        End If
    End Sub
    can u stop using Split?
    also your coding skills are quite bad if u cant do this simple task.
    please learn the basics! theres a lot of exercises u can do to learn all the common functions.

    also if u need to loop through the text in RichTextBox1
    u can simply do that, instead of removing line by line each time.
    loop everything and when done u can erase the entire text in one go.
    if so the first example I gave u can do that if u follow the idea.
    Last edited by baka; Aug 13th, 2022 at 06:22 AM.

  12. #12
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,430

    Re: Vb6: read richtextbox line by line; out of string space

    Quote Originally Posted by vb6s View Post
    something like this but i get error out of string space

    Dim arrLines() As String
    arrLines = Split(RichTextBox1.Text, vbCrLf)
    Text1.Text = arrLines(0)


    RichTextBox1.Text = Mid$(RichTextBox1.Text, InStr(1, RichTextBox1.Text, vbCrLf) + 2)
    Do While RichTextBox1.Text = "" = False
    Call Command1_Click
    Loop

    i wana keep running command till richtextbox becomes empty
    I understand your idea, but I think what you are not realizing is that every time that you call Command1_Click, it is doing exactly everything that is inside Command1_Click, including calling Command1_Click again, and again, and again.

    Usually when we need to do something like that, and want to avoid this issue, put a flag.
    In this case you could use the Tag property or if you prefer you could use a module level variable or a local but Static variable.

    Example with the Tag Property:

    Code:
    Private Sub Command1_Click()
        Dim arrLines() As String
        
        arrLines = Split(RichTextBox1.Text, vbCrLf)
        Text1.Text = arrLines(0)
        
        
        RichTextBox1.Text = Mid$(RichTextBox1.Text, InStr(1, RichTextBox1.Text, vbCrLf) + 2)
        If Command1.Tag = "" Then
            Command1.Tag = "1"
            Do While RichTextBox1.Text = "" = False
                Call Command1_Click
            Loop
            Command1.Tag = ""
        End If
    End Sub
    I have no idea if your code works (I didn't look to it closely), and I'm not saying that's the way to solve your problem. It is just to point how to call something recursively without entering a endless loop, or even if it finishes at some point, maybe too deep loop (the VB stack is limited to a number of levels).

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,671

    Re: Vb6: read richtextbox line by line; out of string space

    Ouch. Things are just getting scarier.

    "VB stack?" "Levels?"

    Sure stack overflow is a thing but it doesn't work that way. And he isn't even getting that far because the crazy code fails before that. The flag-and-Tag thing is just nuts.

    I pity anyone stumbling on this thread in the future. Shouldn't satire threads go into Chit-Chat?

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,095

    Re: Vb6: read richtextbox line by line; out of string space

    I have no idea why you think you need to keep callign command1 nor can I determine why no one has mention using a simple loop but

    Code:
    Dim arrLines() As String
    Dim x As Long
    arrLines = Split(RichTextBox1.Text, vbCrLf)
    For x = 0 To UBound(arrLines)
        Text1.Text = arrLines(x)
        RichTextBox1.Text = Mid$(RichTextBox1.Text, InStr(1, RichTextBox1.Text, vbCrLf) + 2)
    Next
    Not tested of course but should give you the results you seemed to be trying for in the first post without the string space error and without getting caught in an infinite loop or throwing a stack error. Of course what you would actually see on screen is just the last line from the rtb in text1 and it will process all of those lines so fast you will never see any of them appear until the end.

    If your intent is to be able to see the text appear in the text box and removed from the rtb line by line in a way the user can watch this happen and see what is going on then you need to slow it down. A timer would probably be your best option here but that would require some different coding methods.

  15. #15
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,430

    Re: Vb6: read richtextbox line by line; out of string space

    Redacted (before posting).

    I'll follow my rule of not answering this kind of messages.
    I can say that now, at least once, I did it.

  16. #16
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,387

    Re: Vb6: read richtextbox line by line; out of string space

    this code (post # 8 by baka) should be exactly what you want (in your Command1 Click event)....no other code necessary

    Code:
        Dim Find&    
        Find = InStr(RichTextBox1.Text, vbCrLf)
        If Find > 0 Then
            Text1.Text = Left$(RichTextBox1.Text, Find - 1)
            RichTextBox1.Text = Right$(RichTextBox1.Text, Len(RichTextBox1.Text) - Find)
        End If
    However, clicking that button 5 thousand times is a ridiculous thing to require of a user. WHAT is the purpose in doing this anyway? (A timer was mentioned above which could be used to 'step through' the RTB if one doesn't want to wear out his/her mouse button.---but again, WHY are you wanting to do any of this?)
    Last edited by SamOscarBrown; Aug 13th, 2022 at 08:10 AM.
    Sam I am (as well as Confused at times).

  17. #17
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,151

    Re: Vb6: read richtextbox line by line; out of string space

    VB6s, just to say it, you're making thousands of copies of your arrLines() array, and that's almost certainly your problem. I forget how much stack space you're allocated by default in VB6, but you're possibly over-running that as well. Study about "recursion" and you should see your problem. You've GOT to do it another way, of which there are many.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

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