-
Aug 12th, 2022, 02:33 PM
#1
Thread Starter
Member
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
-
Aug 12th, 2022, 04:29 PM
#2
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).
-
Aug 12th, 2022, 05:06 PM
#3
Thread Starter
Member
Re: Vb6: read richtextbox line by line; out of string space
Originally Posted by SamOscarBrown
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
-
Aug 12th, 2022, 05:37 PM
#4
Re: Vb6: read richtextbox line by line; out of string space
-
Aug 12th, 2022, 05:56 PM
#5
Re: Vb6: read richtextbox line by line; out of string space
Originally Posted by vb6s
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.
-
Aug 12th, 2022, 06:45 PM
#6
Re: Vb6: read richtextbox line by line; out of string space
Originally Posted by SamOscarBrown
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.
-
Aug 13th, 2022, 12:36 AM
#7
Thread Starter
Member
Re: Vb6: read richtextbox line by line; out of string space
Originally Posted by OptionBase1
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
-
Aug 13th, 2022, 02:02 AM
#8
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.
-
Aug 13th, 2022, 05:34 AM
#9
Thread Starter
Member
Re: Vb6: read richtextbox line by line; out of string space
Originally Posted by baka
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 ?
-
Aug 13th, 2022, 05:37 AM
#10
Thread Starter
Member
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.
-
Aug 13th, 2022, 06:14 AM
#11
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.
-
Aug 13th, 2022, 06:51 AM
#12
Re: Vb6: read richtextbox line by line; out of string space
Originally Posted by vb6s
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).
-
Aug 13th, 2022, 07:03 AM
#13
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?
-
Aug 13th, 2022, 07:08 AM
#14
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.
-
Aug 13th, 2022, 07:19 AM
#15
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.
-
Aug 13th, 2022, 08:06 AM
#16
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).
-
Aug 13th, 2022, 08:44 AM
#17
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. 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|