Solved

Richtextbox and Telnet

Posted on 2000-05-12
30
482 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:thunderchicken
  • 11
  • 7
  • 4
  • +4
30 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
"It takes a text string and replaces arbitary sequences with ANSI color codes, good for telnet servers. Does not touch on positioning, but a text file with a list of control codes is included."

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=1000



another sample here

http://provivo.hypermart.net/vb/
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
http://www.fastlane.net/~storrs/video/telnet.zip
"Updated VB5 telnet code, with bug fixes and support for ANSI, VT52 and VT100"
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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.
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
how vital is it to use the richtextbox for you?
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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.
0
 
LVL 9

Expert Comment

by:GivenRandy
Comment Utility
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!
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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
0
 
LVL 9

Expert Comment

by:GivenRandy
Comment Utility
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
0
 
LVL 9

Expert Comment

by:GivenRandy
Comment Utility
The core code is:

RichTextBox1.SelStart = 3 ' Some Start Value
RichTextBox1.SelLength = 5 ' Some Length Value
RichTextBox1.SelColor = vbRed ' Some Color


0
 
LVL 4

Expert Comment

by:Juilette
Comment Utility
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



0
 
LVL 4

Expert Comment

by:Juilette
Comment Utility
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
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
Reviewing question.

darinw
Customer Service
0
 

Expert Comment

by:Randy T
Comment Utility
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
0
 
LVL 11

Accepted Solution

by:
thunderchicken earned 0 total points
Comment Utility
Man, it's hard, I had to manipulate the characters one by one and it's still not working right...  I thought I had it done, but it got all messed up so I had to start from scratch.  I may just swallow my pride and use a label, because there are NO resources anywhere on doing this, but I know it can be done.  I've put in about 50 hours just to this one problem and i am still back to square one.  I just figured Microsoft would just convert the dang string for me in a function, heh heh, no good.  

Stripping the characters isn't a problem ofcourse, but it's a pain in the butt with this richtextbox.  I don't know if it would be easier to use a regular textbox with the forecolor property...  I haven't looked into that yet, but who knows.  I'm at work now, but when I get home, I'll post what I have.  I've bought about 200 points in VB help questions and it still hasn't gotten me any further.  The best way to approach this is the following, which I've gotten the best results so far...

1. Strip out all characters except the printable, the escape and the carrage return

2. If ASC(char) = 27 then get the ANSI code by looking at the x+2, x+3 characters, 30's are forecolor I think and 40's are backcolors.  I've only been working with the forecolors.  Once you get this far, you have to go ahead in the string and find either an escape character or the carrage return, then send the string to Juliette's function of

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

They are just not coming out right.  I DID have it where it did the colors right but all the new colors were at the beginning of the buffer or string, but when I saved it in VB, i forgot you have to save the code, and I just saved the form.  I think this was the closest and I understand now why it's doing it.  I wish I would have saved it right  :)

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:darinw
Comment Utility
Community Support has reduced points from 200 to 0
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
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
0
 
LVL 3

Expert Comment

by:darinw
Comment Utility
Comment accepted as answer
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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
0
 

Expert Comment

by:Randy T
Comment Utility
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.
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
i haven't had a bit of problem...  i'll post my code when i get home (in 90 minutes)
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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
0
 

Expert Comment

by:Randy T
Comment Utility
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.
0
 

Expert Comment

by:Randy T
Comment Utility
Heh, apparently I didn't figure it out, it was sitting right in front of me and I didn't know it. :)
0
 

Expert Comment

by:Randy T
Comment Utility
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.
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
Do you lose random characters or do you lose "packets" ?
0
 

Expert Comment

by:Randy T
Comment Utility
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.
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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  :)
0
 

Expert Comment

by:Randy T
Comment Utility
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.
0
 
LVL 11

Author Comment

by:thunderchicken
Comment Utility
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.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now