It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Colorizing RichTextBox output problem...

Moderator: dafunkymunky

Colorizing RichTextBox output problem...

Postby MarioToad on Tue Feb 24, 2009 6:18 pm

Hello, I'm having a crazy issue with my RTB not displaying the correct colors. I'll be more specific...I downloaded the "ImagicaTelnet Client" which comes as VB source code. It says that it supports ANSI color, but I had to change around some of their code to even make it display a color. Finally, I have it to the point where it displays every color execept BWHITE correctly in the "color guide" on a particular server, but the rest of the output doesn't seem to be colored the way it should be. I'm comparing the output from Imagica to the output from another well-programmed telnet client. (Please see pictures.)

Image


Image


Here is the code...it is simply a modified version of the freely downloadable ImagicaTelnet client (which you can get at a number of different free download sites, just search). All I did was change the one sub and one function (see below). These are two procedures that must have some kind of error, but I can't figure it out! Here they are:


Code: Select all
Sub AddColText(sOutput As String)

'On Error Resume Next
Dim CcStart, CcEnd
Dim ANSIprefix
Dim cCode As Integer
Dim StartCcP, EndCcP, oldSel, OldLen

CcStart = (Chr(27) + "[")       ' this is the beginning of an ANSI color code.
CcEnd = "m"                     ' this is the end of an ANSI color code.

Do
    Textboxtmp.SelStart = Len(Textboxtmp.Text)
    Textboxtmp.SelColor = RGB(175, 175, 175)
    Textboxtmp.SelBold = False
    Textboxtmp.SelUnderline = False
    Textboxtmp.SelItalic = False
    Textboxtmp.SelLength = 0
   
    StartCcP = InStr(sOutput, CcStart)
    If StartCcP < 1 Then
        Exit Do
    End If
   
    EndCcP = InStr(StartCcP, sOutput, CcEnd)
   
    If EndCcP < 1 Then
        Exit Do
    End If
   
    ' this procedure determines whether the color code is BRIGHT or NORMAL.
    ANSIprefix = Mid(sOutput, StartCcP + Len(CcStart) + 2, 2)

    If ANSIprefix = "1;" Then
        ' this procedure strips the BRIGHT color code and adds 100 to cCode.
        cCode = Val(Mid(sOutput, StartCcP + Len(CcStart) + 4, 2))
        cCode = cCode + 100
    Else
        cCode = Val(ANSIprefix)
    End If

    Textboxtmp.SelColor = lastcolor
   
    If cCode = 30 Then
        lastcolor = RGB(75, 75, 0)          ' ???
    ElseIf cCode = 31 Then
        lastcolor = RGB(75, 75, 75)         ' BLACK
    ElseIf cCode = 32 Then
        lastcolor = RGB(175, 0, 0)          ' RED
    ElseIf cCode = 33 Then
        lastcolor = RGB(0, 175, 0)          ' GREEN
    ElseIf cCode = 34 Then
        lastcolor = RGB(175, 175, 0)        ' YELLOW
    ElseIf cCode = 35 Then
        lastcolor = RGB(0, 0, 175)          ' BLUE
    ElseIf cCode = 36 Then
        lastcolor = RGB(175, 0, 175)        ' MAGENTA
    ElseIf cCode = 37 Then
        lastcolor = RGB(0, 175, 175)        ' CYAN
    ElseIf cCode = 130 Then
        lastcolor = RGB(175, 175, 175)      ' WHITE
    ElseIf cCode = 131 Then
        lastcolor = RGB(125, 125, 125)      ' BBLACK
    ElseIf cCode = 132 Then
        lastcolor = RGB(255, 0, 0)          ' BRED
    ElseIf cCode = 133 Then
        lastcolor = RGB(0, 255, 0)          ' BGREEN
    ElseIf cCode = 134 Then
        lastcolor = RGB(255, 255, 0)        ' BYELLOW
    ElseIf cCode = 135 Then
        lastcolor = RGB(0, 0, 255)          ' BBLUE
    ElseIf cCode = 136 Then
        lastcolor = RGB(255, 0, 255)        ' BMAGENTA
    ElseIf cCode = 137 Then
        lastcolor = RGB(0, 255, 255)        ' BCYAN
    ElseIf cCode = 138 Then
        lastcolor = RGB(255, 255, 255)      ' This line does not work.
    End If
   
    Textboxtmp.SelColor = lastcolor
    Textboxtmp.SelText = Left(sOutput, StartCcP - 1)
   
    sOutput = Mid(sOutput, EndCcP + 1)
    TextBox.SelStart = StartCcP
    TextBox.SelLength = 0
   
Loop

Textboxtmp.SelText = sOutput
Textboxtmp.SelStart = Len(Textboxtmp.Text)

TextBox.SelStart = oldSel
TextBox.SelLength = OldLen

End Sub




Any and all help is greatly appreciated at this point! Good luck figuring this one out. This has stumped me for a long time.

BTW- The server that i am logging into is LegendMUD @ mud.legendmud.org:9999

-={ MarioToad }=-
Last edited by MarioToad on Tue Feb 24, 2009 10:44 pm, edited 1 time in total.
MarioToad
 
Posts: 2
Joined: Tue Feb 24, 2009 6:11 pm

Re: Colorizing RichTextBox output problem...

Postby MarioToad on Tue Feb 24, 2009 7:58 pm

After removing the On Error Resume Next, i did not receive any errors when i ran the client. im still getting a CYAN color for BWHITE. as well as, overlapping colors and outright wrong colors. This server that I am using outputs standard ANSI color codes like ".[0;30m" for normal colors and a code like ".[0;1;30m" for bright colors (where the . is a Chr(27) ).

This is the RAW, ANSI-CODED "prompt":
Image

So, we have the procedure to determine whether it is bright or normal, and the procedure to strip the color code. Then, we convert it to RGB using the retColorCode function, returning that value to the AddColText subroutine. That sub then outputs text to an RTB in its corresponding color.

I'm not sure what's going on still. The best thing to do is to download ImagicaTelnet, open in VB6, change the sub and that function to what I've got. Log into any MUD that supports ANSI color. Then, try to get it working. I can't seem to do it. LegendMUD has a command called "color guide" that displays all the colors and their numbers. While that displays everything correctly except BWHITE (displays as CYAN), the rest of the MUD output like room descriptions, the score, the main prompt, etc. are miscolored still.

I'm sure anyone can recreate the same scenario on their machine. If there is something I need to add, change, or take out to make this work, it would be awesome! It seems to _almost_ work perfectly. Getting this color issue out of the way is going to free me up for further work on the whole project.
MarioToad
 
Posts: 2
Joined: Tue Feb 24, 2009 6:11 pm


Who is online

Users browsing this forum: No registered users and 4 guests