rtb.selcolor
If I put breaks on the three tmpTStart, I can see the text turning the proper color. When I hit F5, it reverts back to the default color for the box. I have no clue why it would do that. I don't see a clear flaw in the code, but I never could figure out selcolor very well; so, can anyone point out where I'm making the mistake?
Dim tmpTStart As Integer, x as integer 'TB as richtextbox
For x = 0 To TotalItems - 1
With TB
tmpTStart = Len(.Text)
.Text = .Text & Newitem
.SelStart = tmpTStart
.SelLength = Len(Newitem)
.SelColor = vbGreen
tmpTStart = Len(.Text)
.Text = .Text & "="
.SelStart = tmpTStart
.SelLength = Len("=")
.SelColor = vbRed
tmpTStart = Len(.Text)
.Text = .Text & NewValue
.SelStart = tmpTStart
.SelLength = Len(NewValue)
.SelColor = vbBlue
End With
Next x
[986 byte] By [
liolixli] at [2007-11-11 10:04:21]

# 1 Re: rtb.selcolor
coz it pass throw the loop very fast , u may break between them using the sleep() function with a proper wait time 100 say .. to be able to see the color changes .
Amahdy at 2007-11-11 17:23:17 >

# 2 Re: rtb.selcolor
I mean that I want it to stay that color. Can someone explain why it doesn't stay that color.
# 3 Re: rtb.selcolor
every time you start selection from the same point : " .SelStart = tmpTStart "
you must choose a new location like : "tmpTStart + Len(Newitem)" for example .
Amahdy at 2007-11-11 17:25:16 >

# 4 Re: rtb.selcolor
every time you start selection from the same point : " .SelStart = tmpTStart "
you must choose a new location like : "tmpTStart + Len(Newitem)" for example .
Len(.Text) is a dynamic location. The text is being updated; thus, the end of the text is a new location everytime.
Look... All the selection points are correct. Did I not tell you that it changes them initially? Why would it change them initially if I had the wrong .selstarts? The problem is they don't stay changed. Unless you can point out specifically where tmptstart = 0 after the initial item. For the text though len(.text) will always be 0 + X; tmptstart should never equal 0 again.
# 5 Re: rtb.selcolor
How could it be dynamic in a for loop ? if len(.text) = 5 it will still 5 until at least one for loop is done then the start point is the same .
If it's dynamic u can use the keyword : DoEvents in the for loop body to let the location changes when the loop execute .
or explain more how is your text and variables look like , a small example with numbers .
Amahdy at 2007-11-11 17:27:17 >

# 6 Re: rtb.selcolor
How could it be dynamic in a for loop ? if len(.text) = 5 it will still 5 until at least one for loop is done then the start point is the same .
If it's dynamic u can use the keyword : DoEvents in the for loop body to let the location changes when the loop execute .
or explain more how is your text and variables look like , a small example with numbers .
it does not say len(".text") it says len(.text) It is a variable not a constant string. I appreciate your help, but I don't think you can answer the question. My code is 100% correct. The trouble is only in how to properly use the .selcolor method. Obviously, I'm not using it correctly; that is the place the problem is and the question I asked initially. The rest of my code doesn't need any attention... It all works fine.
IE: like I said the text all changes fine initially. The last line printed looks fine, but it reverts back to the default selcolor for all the text when it moves to new lines, but at no point should that happen, unless I am missing something with how to use .selcolor.
# 7 Re: rtb.selcolor
here is the code again, but it will make more sense this way. It uses the method you said you understood better. Only the last line ends up the proper color.
For x = 0 To TotalItems - 1
If x = 0 Then
TB.Text = Item(x) & "=" & ItemValue(x)
Else
TB.Text = TB.Text & vbNewLine & Item(x) & "=" & ItemValue(x)
End If
With TB
.SelStart = tmpTStart
.SelLength = Len(Item(x))
.SelColor = vbGreen
tmpTStart = tmpTStart + Len(Item(x))
.SelStart = tmpTStart
.SelLength = Len("=")
.SelColor = vbRed
tmpTStart = tmpTStart + Len("=")
.SelStart = tmpTStart
.SelLength = Len(ItemValue(x))
.SelColor = vbBlue
tmpTStart = tmpTStart + Len(ItemValue(x)) + Len(vbNewLine)
End With
Next x
# 8 Re: rtb.selcolor
Oh my god ! I puted 5 for example I dont mean at all the constant string !!
I know what I do and what I say "liol" , the problem seems in your code and u can't confirm that your code is correct or not anyway !!
if u have understood my post I'm talking about executing two process at the same time coulden't be done until u make doevents .. the for loop will never exit it's process to make the update in any place into your application like you mentioned so the length of your text will be constant at least for the same loop !
Amahdy at 2007-11-11 17:30:24 >

# 9 Re: rtb.selcolor
your code is wrong look here :
For x = 0 To TotalItems - 1
If x = 0 Then
TB.Text = Item(x) & "=" & ItemValue(x)
Else
TB.Text = TB.Text & vbNewLine & Item(x) & "=" & ItemValue(x)
End If
With TB
.SelStart = tmpTStart
.SelLength = Len(Item(x))
.SelColor = vbGreen
.SelStart = tmpTStart + Len(Item(x))
.SelLength = Len("=")
.SelColor = vbRed
.SelStart = tmpTStart + Len("=")
.SelLength = Len(ItemValue(x))
.SelColor = vbBlue
tmpTStart = len(TB.Text)
End With
Next x
What about it now ?
Amahdy at 2007-11-11 17:31:21 >

# 10 Re: rtb.selcolor
Ok, to humor you, I put a doevents after everyline... just to rule that out. Even with 15 doevent statements, the same result. So, even if you know what you are talking about, it doesn't apply in this case. I appreciate help always, but your arrogance is absurd. Just because you don't know, doesn't mean you have to become rude.
# 11 Re: rtb.selcolor
All you did was hardcode what I already had, but you made it so it will only work when x = 0.
With TB
.SelStart = tmpTStart
.SelLength = Len(Item(x))
.SelColor = vbGreen
.SelStart = tmpTStart + Len(Item(x))
.SelLength = Len("=")
.SelColor = vbRed
.SelStart = tmpTStart + Len("=")
.SelLength = Len(ItemValue(x))
.SelColor = vbBlue
tmpTStart = len(TB.Text)
End With
Next x
With TB
.SelStart = tmpTStart
.SelLength = Len(Item(x))
.SelColor = vbGreen
tmpTStart = tmpTStart + Len(Item(x))
.SelStart = tmpTStart
.SelLength = Len("=")
.SelColor = vbRed
tmpTStart = tmpTStart + Len("=")
.SelStart = tmpTStart
.SelLength = Len(ItemValue(x))
.SelColor = vbBlue
tmpTStart = tmpTStart + Len(ItemValue(x)) + Len(vbNewLine)
End With
Next x
# 12 Re: rtb.selcolor
Your method will not let u learn anything !
My moral don't let me continue reply to u and very sorry for trying helping u !
Only I'm looking for any admin to make anything for u coz this forum isn't for ppl like u who insulte members even u still in the wrong way .
Amahdy at 2007-11-11 17:34:25 >

# 13 Re: rtb.selcolor
I don't insult you. You simply have the wrong solutions and I have to keep explaining to you why they are wrong instead of trying to understand something that actually helps me. I am being very polite in taking the time to understand you and explain that much for you. Like I said, being wrong should not be insulting, but you are being rude about it and keep telling me somehow something else is wrong that isn't.
# 14 Re: rtb.selcolor
as I told u by your method you will not learn anythink, ppl like u can't talk about polite .
I haven't gived u wrong answers , that's only u don't want to understand that's all .
*in your first code you had a problem with the start selection in the same loop
**in the next code [I haven't seen the third line but anyway] u don't take the best starting point in the next loop
***your third code comparing with mine guess what is the difference ?
finally just tell me what does this mean : "but your arrogance is absurd" it's not from my pocket , in my country we r as polite as considering this an insult if u don't know but if it's true in me I'll try to change it hope u change yours .
Amahdy at 2007-11-11 17:36:29 >

# 15 Re: rtb.selcolor
two things for anyone who reads this...
First, the code is not directly my code. I trimmed the names and gave the principle of what it does.
Second, I want to know Why does the entire text turn green other than the last line? I do not care how any of the rest of the code works or looks I just want that one simple answer. I don't need code rewritten or suggestions to better it. I just need someone who knows what they are saying to explain why it would revert back text that is already changed. I tested all the variables and selstart never = 0 after the first time, so there is no way it should ever reselect the previous text.
# 16 Re: rtb.selcolor
After adding the sleep function and watching it draw the text, I finally realized that doing text = text + new text... It was recognizing that text as a new input and formating it as so. That would have been a really easy explaination. I can't believe I was missing that.
# 17 Re: rtb.selcolor
Thanks to IRC and inuyasha. Took him/her 3 seconds to explain my error and how to fix it. apparently rtb works better when using seltext method, which I had not been accustomed to using.
For x = 0 To .TotalItems - 1
If x = 0 Then
.SelColor = vbGreen
.SelText = .CItem(x)
.SelColor = vbRed
.SelText = "="
.SelColor = vbBlue
.SelText = .CItemValue(x)
Else
.SelText = vbNewLine
.SelColor = vbGreen
.SelText = .CItem(x)
.SelColor = vbRed
.SelText = "="
.SelColor = vbBlue
.SelText = .CItemValue(x)
End If
Next x
# 18 Re: rtb.selcolor
Second, I want to know Why does the entire text turn green other than the last line? I do not care how any of the rest of the code works or looks I just want that one simple answer.
aren't u the poster of this :
When I hit F5, it reverts back to the default color for the box. I have no clue why it would do that. I don't see a clear flaw in the code, but I never could figure out selcolor very well;
with noting the last change in the first post time and date ...
I don't need code rewritten or suggestions to better it.
I gived u finally a small snap to let u know where r u wrong in maybe u could understand but I have returned with failue !!
I just need someone who knows what they are saying to explain why it would revert back text that is already changed.
I did, I know what I'm saying but u don't , understand anything in anything more , that's your problem !
I tested all the variables and selstart never = 0 after the first time, so there is no way it should ever reselect the previous text.
First line demonstrating that u don't understand anything .. don't tell me with last updated code !
After adding the sleep function and watching it draw the text,
I told u sleep coz u have writen this :
If I put breaks on the three tmpTStart, I can see the text turning the proper color.
And I have told u doevents coz u have writen this :
Len(.Text) is a dynamic location. The text is being updated; thus, the end of the text is a new location everytime.
and this is the second line demonstrating that u don't understand anything !
however I asked u that :
If it's dynamic u can use the keyword : DoEvents in the for loop body to let the location changes when the loop execute .
or explain more how is your text and variables look like , a small example with numbers .
I finally realized that doing text = text + new text... It was ...
Haven't I said that from my second post [post number 4] ?? :
" every time you start selection ... like : "tmpTStart + Len(Newitem)" for example . "
***If u think that I'm giving u better code only so u r wrong as usually , I gived u better and correct code together, I'm not the best one usually there are ppl better than me and I'm happy that I can still learn from them ..
***Tell inuyasha good coding but he must care in large text amount when the text length exeede the integer limit the seltext will not continue and gives errors .
Amahdy at 2007-11-11 17:40:34 >

# 19 Re: rtb.selcolor
I'm very said to see this in a dev. forum , I have just posted this last one to tell him and anyone reads this what's the point is , but I think after that it's better to remove all unrelated postes or the thread itself .. it's not good to see this here :(
I hope that any admin do any action in this , that's will be better for our forum ..
Thank u .
Amahdy at 2007-11-11 17:41:31 >

# 20 Re: rtb.selcolor
what you said was not good english and not understandable. I really can't tell what you were trying to say. Either way, it was my post and all you did was cause trouble and prevent anyone else from helping. If the admin looks at anything I hope it is your actions. I wasn't trolling around your posts causing trouble and speaking in a way that would take a translator to read.
# 21 Re: rtb.selcolor
...and very sorry for trying helping u !
u don't understand that's ok it's normal ..
but look in all my posts every body understand !
and who told u that if anybody reply in such a post that prevent others to reply ? maybe they know who r u so they stop replying .
Amahdy at 2007-11-11 17:43:42 >
