Valhalla Legends Forums Archive | Battle.net Bot Development | AddChat Procedure

AuthorMessageTime
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.

[code]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[/code]

Example:
[code]AddChat AC_ITALIC_ON, vbWhite, "Hello ", vbRed, " there.", AC_ITALIC_OFF, vbWhite, AC_BOLD_ON, " BOLD!"[/code]
Output:
[quote][color=white]Hello[/color] [color=red]there.[/color] [color=white]BOLD![/color][/quote]

[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.
May 24, 2006, 9:44 AM
Myndfyr
Out of curiousity, why didn't you just make a bitmask for what things you wanted?

[code]
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
[/code]
May 24, 2006, 6:19 PM
Topaz
Interesting.
May 24, 2006, 11:38 PM
FrOzeN
[quote author=MyndFyre[vL] link=topic=15044.msg153092#msg153092 date=1148494748]
Out of curiousity, why didn't you just make a bitmask for what things you wanted?

[code]
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
[/code]
[/quote]

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.
May 25, 2006, 2:50 AM
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:
[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[/code]

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

Thank you.
June 20, 2006, 6:38 AM
Myndfyr
My chat-adding routine includes a timestamp based on a bitmask.  The time stamp is built within the add-chat function itself, not outside.
June 20, 2006, 9:28 AM
rabbit
Maybe if you didn't use a poorly written AddChat routine....
June 20, 2006, 1:13 PM
DeathSoldier
[quote author=rabbit link=topic=15044.msg154669#msg154669 date=1150809237]
Maybe if you didn't use a poorly written AddChat routine....
[/quote]
Instead of bashing the code, why not post a 'well' writting AddChat routine?
June 21, 2006, 12:52 AM
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.
June 21, 2006, 10:23 AM
rabbit
[quote author=DeathSoldier link=topic=15044.msg154708#msg154708 date=1150851158]
[quote author=rabbit link=topic=15044.msg154669#msg154669 date=1150809237]
Maybe if you didn't use a poorly written AddChat routine....
[/quote]
Instead of bashing the code, why not post a 'well' writting AddChat routine?
[/quote]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.
June 21, 2006, 12:34 PM
Spht
[quote author=rabbit link=topic=15044.msg154727#msg154727 date=1150893278]
[quote author=DeathSoldier link=topic=15044.msg154708#msg154708 date=1150851158]
[quote author=rabbit link=topic=15044.msg154669#msg154669 date=1150809237]
Maybe if you didn't use a poorly written AddChat routine....
[/quote]
Instead of bashing the code, why not post a 'well' writting AddChat routine?
[/quote]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.
[/quote]

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

[code]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[/code]

See the original post here.
June 24, 2006, 12:32 AM
rabbit
Hm.  It still works.  And I do remember it from somewhere.
June 24, 2006, 12:07 PM
UserLoser
What's with the 50000?  Random number some newbie used I guess :)
June 25, 2006, 5:40 AM
FrOzeN
[quote author=UserLoser link=topic=15044.msg154924#msg154924 date=1151214057]
What's with the 50000?  Random number some newbie used I guess :)
[/quote]
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.
June 25, 2006, 8:15 AM
UserLoser
Seems like a stupid way to do it
June 25, 2006, 6:21 PM

Search