• Welcome to Valhalla Legends Archive.
 

Parsing the colors

Started by Networks, May 04, 2004, 08:58 AM

Previous topic - Next topic

FuzZ

#15
Quote from: Eli_1 on May 04, 2004, 07:05 PM

If InStr(Message, "Á", vbTextCompare) >= 1 Then
   MsgBox "Found Á"e
end if


That's not the syntax InStr takes.
It should be InStr(Start, S1, S2, Seach type).
Your doing InStr(S1, S2, Search type).

This should work:


InStr(1, Message, "Á", vbTextCompare) >= 1 Then
   MsgBox "Found Á"e
end if



And to BaDDBLooD,
If InStr(1, Message, "Á", vbTextCompare) = 1 Then.
InStr returns the first instance of the "search string" (Á in this instance). That's why you do <> 0. InStr can return any number greater than 0, and less than or equal to Len(Message) -- depending on where in the string Á is.



Start is optional.

Edit> The search type is optional as well, I use alot of InStr("Haystack", "Needle") <> 0

BaDDBLooD

if i didn't have start, it gave me a error :|
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Eli_1

Ok, I got it fixed. If you copy and paste this in a new project, then it will run. If it doesn't run, you suck :X.

ASSUMES: You have a RichTextBox on the form named txtOutput

Code:


Private Sub Form_Load()
'// Put me somewhere  :P
Const Message As String = "ÁU%%%%%%%%%%%%%%%%%%%%%%%%%%%%ÁYI'm" & _
vbCrLf & "ÁU%%%%%%%%%%%%%%%%%%%%%%%%%%%%ÁVA" & _
vbCrLf & "ÁU%%%%%%%%%%%%%%%%%%%%%%%%%%%%ÁRLoser" & _
vbCrLf & "ÁU%%%%%%%%%%%%%%%%%%%%%%%%%%%%ÁVWith" & _
vbCrLf & "ÁU%%%%%%%%%%%%%%%%%%%%%%%%%%%%ÁYA" & _
vbCrLf & "ÁU%%%%%%%%%%%%%%%%%%%%%%%%%%%%ÁYFÁZLÁYoÁYoÁVD ÁUBÁVoÁRT!" _
& vbCrLf
'/* This example will Split this string. */


Dim ColorParse() As String
'/* MerF!? */

Dim ColorByte As String
'/* This is just to make the code a little
'** easier to read. */

If InStr(1, Message, "Á", vbTextCompare) <> 0 Then
   ColorParse = Split(Message, "Á")
   AddText txtOutput, vbYellow, "<FLooD_iZ_LaME> "
   For i = 0 To UBound(ColorParse)
       If ColorParse(i) <> "" Then
           ColorByte = Left(ColorParse(i), 1)
           ColorParse(i) = Right(ColorParse(i), Len(ColorParse(i)) - 1)
           AddText txtOutput, GetColor(ColorByte), ColorParse(i)
       End If
   Next i
End If

End Sub

Private Function GetColor(ByVal ColorByte As String) As ColorConstants
   Select Case ColorByte
   Case "Y": GetColor = vbRed
   Case "U": GetColor = vbCyan
   Case "R": GetColor = vbYellow
   Case "V": GetColor = vbGreen
   Case "Z": GetColor = vbMagenta
   End Select
End Function

Private Function AddText(OutputTO As RichTextBox, _
ByVal Color As ColorConstants, _
ByVal Data As String)
   With OutputTO
       .SelStart = Len(.Text)
       .SelColor = Color
       .SelText = Data
       .SelStart = Len(.Text)
   End With
End Function

BaDDBLooD

#18
Yo dude, try this for your Message Constant:

[7:51:12 PM] <sCaReD@Azeroth ÁQ.::.ÁRFÁPlawedÁQ-ÁRBÁPotÁQ.::. ÁR|ÁQ-v1.17c-ÁR| ÁQ---.ÁRBÁPyÁQ.ÁRFÁPleet-ÁQ>

doesn't work ;p
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Eli_1

#19
That happens for a reason.
Quote[7:51:12 PM] <sCaReD@Azeroth ÁQ.::.ÁRFÁPlawedÁQ-ÁRBÁPotÁQ.::. ÁR|ÁQ-v1.17c-ÁR| ÁQ---.ÁRBÁPyÁQ.ÁRFÁPleet-ÁQ>
will never be the 'Message'. Considering so many people use CSB, the UserEmote event is raised with these parameters (IIRC).

Username, Message
Quote
Username = sCaReD@Azeroth
Message =  ÁQ.::.ÁRFÁPlawedÁQ-ÁRBÁPotÁQ.::. ÁR|ÁQ-v1.17c-ÁR| ÁQ---.ÁRBÁPyÁQ.ÁRFÁPleet-ÁQ

The timestamp is added seperatly on peoples bots. so are the emote tags (< >). Now, if you try that again using the Message stated above, then it will work -- some characters will appear blank though. That's because I didn't include all the color constants.


Edit:
I changed my GetColor() function to this:
Private Function GetColor(ByVal ColorByte As String) As ColorConstants
   Select Case ColorByte
   Case "Y": GetColor = vbRed
   Case "U": GetColor = vbCyan
   Case "R": GetColor = vbYellow
   Case "V": GetColor = vbGreen
   Case "Z": GetColor = vbMagenta
   Case "Q": GetColor = vbMagenta
   Case "P": GetColor = vbGreen
   End Select
End Function

I changed my Message constant to what's named above and ran the program. This is the output that was shown.
Quote
<FLooD_iZ_LaME> .::.Flawed-Bot.::. |-v1.17c-| ---.By.Fleet-

BaDDBLooD

yes, i know it works. i'm just saying the username is something that you didn't handle :)
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Eli_1

Quote from: BaDDBLooD on May 04, 2004, 08:00 PM
yes, i know it works. i'm just saying the username is something that you didn't handle :)
That's because it is something that should never come up in a real scenario. Username and Message are always seperate and my function assumes that.

BaDDBLooD

Your right.

Thanks you for the Function, can you give me your info so i can Comment you at the top of the code?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

BaDDBLooD

ELi you can im me on aol at BaDD OwNs JoO

i still have some questions :|
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

GoSuGaMING

baddblood didnt you say u were banned from these fourms?

Mephisto

hmm...this has nothing to do with helping, but when you have a single character constant shouldn't you put it in single parenthasis, or does it no matter in VB?

Networks

#26
I don't if this is fixed but I only had one problem with this and it was that it would output the text in my RTB for each split part how can I get it to change the colors in sentence but keep the sentence intact? I don't want it to be like:

Networks
says
hi

When the original sentence is Networks says hi.

By the way I haven't tested the new code but I assuming it still does it the same way and I figured out how yours works.

Eli_1

Your the second person that asked about that. My example uses a very simple AddChat function. Post the AddChat function your using, that's probably your problem.

Networks

If the addtext function works okay then I'll just use that.

Eli_1

Quote from: Mephisto on May 05, 2004, 08:55 AM
hmm...this has nothing to do with helping, but when you have a single character constant shouldn't you put it in single parenthasis, or does it no matter in VB?
I'm assuming your asking that because you program in C++? No, it doesn't matter in VB. There is no such thing as single quotes -- that is reserved for comments.

|