• Welcome to Valhalla Legends Archive.
 

AddChat Procedure

Started by FrOzeN, May 24, 2006, 04:44 AM

Previous topic - Next topic

FrOzeN

Thought I'd share this. Slightly different to the more common methods. It's just ment to be a really simple way of adding text without any format required. Also by expanding vbCurreny constances it could be easily modified to add more abilties to it.

Private Const AC_BOLD_ON As Currency = 0
Private Const AC_BOLD_OFF As Currency = 1
Private Const AC_ITALIC_ON As Currency = 2
Private Const AC_ITALIC_OFF As Currency = 3

Private Sub AddChat(ParamArray Parts() As Variant)
    Dim i As Integer
    With rtbChat
        .SelStart = Len(.Text)
        For i = LBound(Parts) To UBound(Parts)
            .SelLength = 0
            If VarType(Parts(i)) = vbCurrency Then
                Select Case Parts(i)
                    Case 0: .SelBold = True
                    Case 1: .SelBold = False
                    Case 2: .SelItalic = True
                    Case 3: .SelItalic = False
                End Select
            ElseIf (VarType(Parts(i)) = vbInteger) Or (VarType(Parts(i)) = vbLong) Then
                .SelColor = Parts(i)
            Else
                .SelText = CStr(Parts(i))
                .SelStart = Len(.Text)
            End If
        Next i
    .SelText = vbCrLf
    .SelStart = Len(.Text)
    End With
End Sub


Example:
AddChat AC_ITALIC_ON, vbWhite, "Hello ", vbRed, " there.", AC_ITALIC_OFF, vbWhite, AC_BOLD_ON, " BOLD!"
Output:
QuoteHello there. BOLD!

[EDIT] Note: When parsing Integers, Longs or Curreny into the function to be displayed as text. Place CStr() around them to convert them to a string so they don't get interpreted as Colours/Formatting.
~ FrOzeN

MyndFyre

Out of curiousity, why didn't you just make a bitmask for what things you wanted?


Const AC_NONE As Integer = 0  ' Why the hell would you use Currency???
Const AC_BOLD As Integer = 1
Const AC_ITALIC As Integer = 2
Const AC_UNDERLINE As Integer = 4
Const AC_OVERLINE As Integer = 8
Const AC_LINK As Integer = 16
Const AC_AD_NAUSEUM As Integer = &HFFFFFFE0
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

topaz

RLY...?

FrOzeN

#3
Quote from: MyndFyre[vL] on May 24, 2006, 01:19 PM
Out of curiousity, why didn't you just make a bitmask for what things you wanted?


Const AC_NONE As Integer = 0  ' Why the hell would you use Currency???
Const AC_BOLD As Integer = 1
Const AC_ITALIC As Integer = 2
Const AC_UNDERLINE As Integer = 4
Const AC_OVERLINE As Integer = 8
Const AC_LINK As Integer = 16
Const AC_AD_NAUSEUM As Integer = &HFFFFFFE0


It's ment to be able to parse colours, text and formatting. By default, colours are parsed to the sub as Integers/Longs and the sub works by determining what DATA TYPE they are to know how to process them. Because of this for my constances I parse to the sub, I had to use a different data type so it can tell them apart from colours. So I just chose Currency. For any other data types that get parsed to the sub, I assume there text and just add them to get displayed.

If I made the constances as Integers like your code is. There'd be no way to tell 'AC_BOLD' apart from 'vbWhite' when they get parsed, as there both the same value '1'.

Also your right about bitwise, that'd be better. I'll add it in later.
~ FrOzeN

DeathSoldier

2 questions, I hope you can help a friendly kid out  ::)

1. How do I make it so  a time stamp shows before the lines in the color white, right now it just shows it the current color as the text?

2. If I was to turn bold on, then in another word turn italic on, the timestamp would show twice.
^
ex: [2:00 PM] HELLO [2:00 PM] there!

See how it shows the timestamp twice? I am new to vb, can anyone help me?

Current code:
Public Sub AddC(RTB As RichTextBox, ParamArray Parts() As Variant)
    Dim i As Integer
    With RTB
        .SelStart = Len(.Text)
        For i = LBound(Parts) To UBound(Parts)
            .SelLength = 0
            If VarType(Parts(i)) = vbCurrency Then
                Select Case Parts(i)
                    Case 0: .SelBold = True
                    Case 1: .SelBold = False
                    Case 2: .SelItalic = True
                    Case 3: .SelItalic = False
                End Select
            ElseIf (VarType(Parts(i)) = vbInteger) Or (VarType(Parts(i)) = vbLong) Then
                .SelColor = Parts(i)
            Else
                .SelText = "[ " & Time & "] " & CStr(Parts(i))
                .SelStart = Len(.Text)
            End If
        Next i
    .SelText = vbCrLf
    .SelStart = Len(.Text)
    End With
End Sub


Only thing change is the '.SelText = "[ " & Time & "] " & CStr(Parts(i)' (the adding of "[ " & Time & "] " &).

Thank you.

MyndFyre

My chat-adding routine includes a timestamp based on a bitmask.  The time stamp is built within the add-chat function itself, not outside.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

rabbit

Maybe if you didn't use a poorly written AddChat routine....
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

DeathSoldier

Quote from: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Instead of bashing the code, why not post a 'well' writting AddChat routine?

FrOzeN

Heh, I know it was a pretty poorly written piece of code. I wasn't really expecting any practical use of it, just posting another method for newcomers to see different ways code can be used.

I'll post a cleaner version tomorrow.
~ FrOzeN

rabbit

Quote from: DeathSoldier on June 20, 2006, 07:52 PM
Quote from: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Instead of bashing the code, why not post a 'well' writting AddChat routine?
People should not be spoonfed.  If I said not to use a "poorly written AddChat routine", it's clearly indicated that there are better routines out there, and he should try searching.  But, because you insist on spoon feeding him, here.  Now be quiet.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Spht

Quote from: rabbit on June 21, 2006, 07:34 AM
Quote from: DeathSoldier on June 20, 2006, 07:52 PM
Quote from: rabbit on June 20, 2006, 08:13 AM
Maybe if you didn't use a poorly written AddChat routine....
Instead of bashing the code, why not post a 'well' writting AddChat routine?
People should not be spoonfed.  If I said not to use a "poorly written AddChat routine", it's clearly indicated that there are better routines out there, and he should try searching.  But, because you insist on spoon feeding him, here.  Now be quiet.

The page says it's Grok's, but it's not.  Grok wouldn't do something as stupid as:

If Len(rtb.text) > 50000 Then
      With rtb
           .Visible = False
           .SelStart = 0
           .SelLength = InStr(1, .text, vbLf, vbTextCompare)
           .SelText = vbNullString
           .Visible = True
      End With
End If


See the original post here.

rabbit

Hm.  It still works.  And I do remember it from somewhere.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

UserLoser

What's with the 50000?  Random number some newbie used I guess :)

FrOzeN

Quote from: UserLoser on June 25, 2006, 12:40 AM
What's with the 50000?  Random number some newbie used I guess :)
It makes it so if the RichTextBox has more than 50 thousand characters in it, it clears the top line. This way it doesn't use up excessive temporary cache.
~ FrOzeN

UserLoser

Seems like a stupid way to do it