thunderchicken
asked on
Richtextbox and Telnet
I want to have ANSI color in the richtextbox when I connect to telnet through the VB program I made. It's connecting now but the formatting is garbled.
Please give me all the code you can for the points! :)
Thunderchicken
Please give me all the code you can for the points! :)
Thunderchicken
http://www.fastlane.net/~storrs/video/telnet.zip
"Updated VB5 telnet code, with bug fixes and support for ANSI, VT52 and VT100"
"Updated VB5 telnet code, with bug fixes and support for ANSI, VT52 and VT100"
ASKER
Ruchi - It didn't have color controls
Azra - Top one didn't work with a rich text box and the bottom one used the form to display stuff, which I didn't understand.
Azra - Top one didn't work with a rich text box and the bottom one used the form to display stuff, which I didn't understand.
how vital is it to use the richtextbox for you?
ASKER
Well, since it's on a form, I need to add command buttons, list boxes and stuff like that to this, if I don't have a textbox, then it wont work because the code is directly on the form. I must have the ANSI color for the application to work, and if it is directly on the form, it will defeat the purpose. Someone told me that a richtextbox would work, I'm still looking for a solution.
Thunderchicken asked that I post this URL here:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=3911
I guess it makes sense to Thunderchicken to do that. All the best in your programming!
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=3911
I guess it makes sense to Thunderchicken to do that. All the best in your programming!
ASKER
I've been looking at zillions of options, I thought that was going to do what it does, but actually that code given was about the same as what azra suggested. It actually sends the ANSI code, but doesn't interepret them. I am currently in the process of writing my own decoding by checking the ASCII value back and forth, but I guess we will see what happens, but thanks!
Dave
Dave
This site has a sample with RichTextBox in colors:
http://www.vbexplorer.com/VB_String_Text.asp
Actual download at:
http://www.vbexplorer.com/files/colortag.zip
http://www.vbexplorer.com/VB_String_Text.asp
Actual download at:
http://www.vbexplorer.com/files/colortag.zip
The core code is:
RichTextBox1.SelStart = 3 ' Some Start Value
RichTextBox1.SelLength = 5 ' Some Length Value
RichTextBox1.SelColor = vbRed ' Some Color
RichTextBox1.SelStart = 3 ' Some Start Value
RichTextBox1.SelLength = 5 ' Some Length Value
RichTextBox1.SelColor = vbRed ' Some Color
thunderchicken:
Sorry, I don't know anything about them...just a few pieces of code I've pulled from here and there...I assume you have these but relating to RichTextBoxes this is all I have:
'change the color of text in a RichTextBox
Sub PrintMessage(MessageText As String, MessageColor As Long, RTFBox As RichTextBox)
RTFBox.SelStart = Len(RTFBox.Text)
RTFBox.SelText = MessageText
RTFBox.SelStart = RTFBox.SelStart - Len(MessageText)
RTFBox.SelLength = Len(MessageText)
RTFBox.SelColor = MessageColor
RTFBox.SelStart = Len(RTFBox.Text)
End Sub
' <<<<<<< event code >>>>>>
PrintMessage "This is a sample message in RED." & vbCrLf, RGB(255, 0, 0), RichTextBox1
If you want a multicolored line use like this:
PrintMessage "Green part ", RGB(0, 255, 0), RichTextBox1
PrintMessage "Blue part" & vbCrLf, RGB(0, 0, 255), RichTextBox1
Note you put vbCrLf only when you want to end the line.
Of course, you can use QBColor instead of RGB, or system color constants, or the color hex value.
'how to remove blank lines from a rich text box
'coded by Mark for a Q & A on Experts Exchange
'http://www.cyberchute.com/rvbus/madmark
'========================= ========== ========== =========
'form event code
'==============
raw = RTB.Text
Clean = ""
temp = ""
Do While InStr(raw, vbCrLf) > 0
marker = InStr(raw, vbCrLf)
If marker > 0 Then
temp = Trim(Left(raw, marker - 1))
If Len(temp) > 0 Then Clean = Clean & temp & vbCrLf
raw = Right(raw, Len(raw) - (marker + 1))
End If
Loop
'
RTB.Text = Clean
Sorry, I don't know anything about them...just a few pieces of code I've pulled from here and there...I assume you have these but relating to RichTextBoxes this is all I have:
'change the color of text in a RichTextBox
Sub PrintMessage(MessageText As String, MessageColor As Long, RTFBox As RichTextBox)
RTFBox.SelStart = Len(RTFBox.Text)
RTFBox.SelText = MessageText
RTFBox.SelStart = RTFBox.SelStart - Len(MessageText)
RTFBox.SelLength = Len(MessageText)
RTFBox.SelColor = MessageColor
RTFBox.SelStart = Len(RTFBox.Text)
End Sub
' <<<<<<< event code >>>>>>
PrintMessage "This is a sample message in RED." & vbCrLf, RGB(255, 0, 0), RichTextBox1
If you want a multicolored line use like this:
PrintMessage "Green part ", RGB(0, 255, 0), RichTextBox1
PrintMessage "Blue part" & vbCrLf, RGB(0, 0, 255), RichTextBox1
Note you put vbCrLf only when you want to end the line.
Of course, you can use QBColor instead of RGB, or system color constants, or the color hex value.
'how to remove blank lines from a rich text box
'coded by Mark for a Q & A on Experts Exchange
'http://www.cyberchute.com/rvbus/madmark
'=========================
'form event code
'==============
raw = RTB.Text
Clean = ""
temp = ""
Do While InStr(raw, vbCrLf) > 0
marker = InStr(raw, vbCrLf)
If marker > 0 Then
temp = Trim(Left(raw, marker - 1))
If Len(temp) > 0 Then Clean = Clean & temp & vbCrLf
raw = Right(raw, Len(raw) - (marker + 1))
End If
Loop
'
RTB.Text = Clean
As an after thought...there are a few gurus on this site. Aaron or Serge especially....post it there, perhpas someone there can help.
http://forums.vb-world.net/forumdisplay.php?forumid=1
http://forums.vb-world.net/forumdisplay.php?forumid=1
ASKER
Yea, this is what I got from your PAQ, it's helped out quite a bit, but I was just seeing if you had the experience with it and also with different colors on every line. Right now I have a black background that will always display in white. The telnet is kind of wierd and all I am doing is looking for an escape, a [, then the code, then an m, and trying to manipulate the string from there. Thanks anyway and I'll keep working on it!
- TC
- TC
Reviewing question.
darinw
Customer Service
darinw
Customer Service
Hey TC,
I was reading your pending deletion of this question and you say you found an answer on your own? Could you help me out a bit, I can get rid of the codes, but still can't get the colors to work.
Thanks dude,
Skippy
I was reading your pending deletion of this question and you say you found an answer on your own? Could you help me out a bit, I can get rid of the codes, but still can't get the colors to work.
Thanks dude,
Skippy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Community Support has reduced points from 200 to 0
Although there isn't a solution as such for this thread, the work is worth saving to the PAQ.
I am refunding the points on the question, reducing them to zero and moving it to the PAQ.
-- I am accepting one of thunderchicken's comments as an answer --
darinw
Customer Service
I am refunding the points on the question, reducing them to zero and moving it to the PAQ.
-- I am accepting one of thunderchicken's comments as an answer --
darinw
Customer Service
Comment accepted as answer
ASKER
I know there's got to be a way to do it though, from a programmer's standpoint, it makes it more fun. If I do find out, I will post it on here because it's been a hard resource to find.
Thanks
Thanks
I have succesfully stripped most colours out. I just can't get the colours to show up in the RTB. Although there is quite a bit of code (if statements and checks through an array) to see if the ansi codes are there. I'm wondering if it is causing any lag to the data coming in.
ASKER
i haven't had a bit of problem... i'll post my code when i get home (in 90 minutes)
ASKER
if you want, post your code and i'll look at it... i think i know what you are talking about, but i forgot what the problem was
I don't think I actually have a problem, yet. I just recently figured out how to set the background and foreground colors. I'm pretty happy with that, if I could get those ansi codes fixed now I'd be pretty much good to go.
Heh, apparently I didn't figure it out, it was sitting right in front of me and I didn't know it. :)
Actually I do sort of have one problem, I sometimes lose text from the MUD. Like some of it goes missing, kinda odd. I'm sure there's a logical explanation for it though.
ASKER
Do you lose random characters or do you lose "packets" ?
Hard to say, just lose some characters sometimes. Like it'll say:
ll. You do this or that.
You know there is something behind that "ll", it just doesn't show it anywhere. Probably my code somewhere.
ll. You do this or that.
You know there is something behind that "ll", it just doesn't show it anywhere. Probably my code somewhere.
ASKER
when doing the string manipulation (taking out the characters from the MUD), you might have missed a thing here or there, just depends on how the algorithm is set up I imagine. I haven't tested for that problem, but from the intro screen, then the flood with the info it worked fine. I havent used it on the actual MUD yet because it doesn't have colors... yet :)
Ah, right now I can play my MUD, just without colors, although it's not that bad since I played for 2 years without colour anyways. ;) But for now I just use another client until mine is done. I'm pretty impressed with what I can do with mine though. I can set triggers, use macros and aliases. Anything I'm missing? I was going to try to use alarms, but I didn't really know how to go about using those. I imagine you'd use a timer and stuff. I can also log to a file.
ASKER
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim buffer, str, t_str As String
Dim x, y, z As Integer
Dim b_char, t_char
Dim f_color As Long
Winsock1.GetData buffer, vbString
For x = 1 To Len(buffer)
b_char = Mid(buffer, x, 1)
If ((Asc(b_char) = 27) Or (Asc(b_char) = 13) Or ((Asc(b_char) > 30) And (Asc(b_char) < 127))) Then
t_str = t_str & b_char
End If ' Takes out all unnecessary characters
Next
buffer = t_str
For x = 1 To Len(buffer)
b_char = Mid(buffer, x, 1)
If Asc(b_char) = 13 Then
If Len(rtbmain.Text) = 0 Then
PrintMessage str & vbCrLf, vbWhite, rtbmain
Else
With rtbmain
.SelStart = Len(rtbmain.Text)
.SelLength = 1
.SelText = .SelText & str & vbCrLf
End With
End If
rtbmain.SelStart = Len(rtbmain.Text)
str = ""
Else
str = str & b_char
End If
Next
End Sub
Sub PrintMessage(MessageText As String, MessageColor As Long, RTFBox As RichTextBox)
RTFBox.SelStart = Len(RTFBox.Text)
RTFBox.SelText = MessageText
RTFBox.SelStart = RTFBox.SelStart - Len(MessageText)
RTFBox.SelLength = Len(MessageText)
RTFBox.SelColor = MessageColor
RTFBox.SelStart = Len(RTFBox.Text)
End Sub
That will display all printable characters plus the carriage return and escape... that's all i have so far and working on the color now.
Dim buffer, str, t_str As String
Dim x, y, z As Integer
Dim b_char, t_char
Dim f_color As Long
Winsock1.GetData buffer, vbString
For x = 1 To Len(buffer)
b_char = Mid(buffer, x, 1)
If ((Asc(b_char) = 27) Or (Asc(b_char) = 13) Or ((Asc(b_char) > 30) And (Asc(b_char) < 127))) Then
t_str = t_str & b_char
End If ' Takes out all unnecessary characters
Next
buffer = t_str
For x = 1 To Len(buffer)
b_char = Mid(buffer, x, 1)
If Asc(b_char) = 13 Then
If Len(rtbmain.Text) = 0 Then
PrintMessage str & vbCrLf, vbWhite, rtbmain
Else
With rtbmain
.SelStart = Len(rtbmain.Text)
.SelLength = 1
.SelText = .SelText & str & vbCrLf
End With
End If
rtbmain.SelStart = Len(rtbmain.Text)
str = ""
Else
str = str & b_char
End If
Next
End Sub
Sub PrintMessage(MessageText As String, MessageColor As Long, RTFBox As RichTextBox)
RTFBox.SelStart = Len(RTFBox.Text)
RTFBox.SelText = MessageText
RTFBox.SelStart = RTFBox.SelStart - Len(MessageText)
RTFBox.SelLength = Len(MessageText)
RTFBox.SelColor = MessageColor
RTFBox.SelStart = Len(RTFBox.Text)
End Sub
That will display all printable characters plus the carriage return and escape... that's all i have so far and working on the color now.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=1000
another sample here
http://provivo.hypermart.net/vb/