Private Sub access_BnetDisconnected()
frmBot.ShowTxt "< Disconnected from Bnet >" & vbCrLf
access.Disconnect
txtChannel.Text = " "
frmBot.ListBox1.Clear
End Sub
how do i make that red in my richtextbox
frmBot.ShowTxt "< Disconnected from Bnet >" & vbCrLf, vbred?
Let's see your ShowTxt() function.
Public Sub ShowTxt(strTxt As String)
'Show text in main chat box, and scroll to end
txtChat.Text = txtChat.Text & "[" & Time & "]" & strTxt
txtChat.SelStart = Len(txtChat.Text)
With txtChat
If Len(.Text) > 31200 Then
txtChat = " "
End If
End With
End Sub
Instead of me modifying your code, may I suggest that you use Grok's excellent AddChat subroutine?
Private Sub AddChat(ParamArray saElements() As Variant)
Dim i As Integer
For i = LBound(saElements) To UBound(saElements) Step 2
With txtChat
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = saElements(i)
.SelText = saElements(i + 1) & Left$(vbCrLf, -2 * CLng((i + 1) = UBound(saElements)))
.SelStart = Len(.Text)
End With
Next i
End Sub
This supports passing text with multiple colors. For example:
AddChat vbWhite, "<", vbYellow, "Spht", vbWhite, "> Hello."
feh...doesnt have string array input, but whatcha gonna do?
Public Enum MyColorConsts
ColInfo = vbYellow
ColAnnounce = vbMagenta
ColMyText = vbWhite
ColMyUn = vbCyan
ColMyEmote = vbYellow
colTalkText = vbWhite
ColTalkUn = vbYellow
ColTalkOpText = vbWhite
ColTalkOpUn = vbWhite
ColTalkBlizText = vbCyan
ColTalkBlizUn = vbCyan
ColEncrypt = vbMagenta
ColProfile = vbWhite
ColChannel = vbGreen
ColJoinPart = vbGreen
ColAnError = vbRed
ColEmote = vbYellow
ColEmoteOp = vbWhite
ColEmoteBliz = vbCyan
ColWhisperUn = vbCyan
ColWhisperText = &H808080
ColWhisperFromUn = vbYellow
ColWhisperFromText = &H808080
End Enum
Public Sub ClearChat()
Dim x, Y As Integer
x = Len(frmMain.txtChat.Text)
If x = 0 Then Exit Sub 'bleh, dont hit then before any connections :(
For Y = 1 To 100
x = InStrRev(frmMain.txtChat.Text, vbCrLf, x, vbBinaryCompare)
If x = 0 Then Exit Sub 'GoTo bailchop
Next
frmMain.txtChat.Text = Right(frmMain.txtChat.Text, Len(frmMain.txtChat.Text) - x)
frmMain.txtChat.SelStart = 0
frmMain.txtChat.SelLength = Len(frmMain.txtChat.Text)
frmMain.txtChat.SelColor = &HA0A0A0
frmMain.txtChat.SelStart = Len(frmMain.txtChat.Text)
frmMain.txtSend.SetFocus
End Sub
Public Sub AddText(style As MyColorConsts, ByVal mytext As String, ByVal UseTimeStamp As Boolean)
Dim x As Integer
Do
x = InStr(x + 1, mytext, "ÿC")
If x > 0 Then
Dim color As ColorConstants
color = 0
Select Case (Mid(mytext, x + 2, 1))
Case "0": color = RGB(208, 208, 208) 'white
Case "1": color = RGB(208, 64, 64) 'red
Case "2": color = RGB(0, 208, 0) 'green
Case "3": color = RGB(88, 88, 208) 'vbBlue
Case "4": color = 0 'fixme:beige
Case "5": color = &H545454 'gray
Case "6": color = vbBlack 'will this show?
Case "7": color = RGB(160, 160, 100) 'fixme:beige
Case "8": color = RGB(208, 136, 0) 'orange
Case "9": color = RGB(208, 208, 80) 'lt.yellow
End Select
'ÿC1 text displays RED text
'ÿC2 text displays GREEN text
'ÿC3 text displays BLUE text
'ÿC4 text displays BEIGE text
'ÿC5 text displays GRAY text
'ÿC6 text displays BLACK text
'ÿC7 text displays BEIGE text
'ÿC8 text displays ORANGE text
'ÿC9 text displays YELLOW text
If color <> 0 Then
Addtext style, Left(mytext, x - 1), usetimestampp
Addtext color, Mid(mytext, x + 3), False
Exit Sub
End If
End If
Loop While x > 0
With frmMain.txtChat
If Len(.TextRTF) > 65535 Then ClearChat
If (UseTimeStamp = True) And (frmSetup.TSType > 0) Then
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = vbWhite
Select Case frmSetup.TSType
Case 1
.SelText = "[" & Zero(DatePart("h", Now), 2) & _
":" & Zero(DatePart("m", Now), 2) & _
":" & Zero(DatePart("s", Now), 2) & _
"] "
Case Else '2
.SelText = "[" & Date & " " & Time & "] "
End Select
End If
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = style
.SelText = mytext
End With
bailchop:
End Sub
hrm, let me break that down in to n00blish for ya
Public Sub AddText(style As ColorConstants, ByVal mytext As String, ByVal UseTimeStamp As Boolean)
With frmMain.txtChat 'NB: this is an rtb, NOT a regular text box!!
If (UseTimeStamp = True) Then
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = vbWhite
.SelText = "[" & Date & " " & Time & "] "
End If
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = style
.SelText = mytext
End With
End Sub
[/quote]
[edit]hrm, i didnt realise that was going to look exactly like what spht posted...
it doesnt because groks sub allows an unlimited amount of input types, longs, strings, integers, dont matter, in your case, you have to use one color, each time.
Although in vb, groks sub would actually be slower, because you dont declare the type the data is, so vb has to figure it out on its own, which can kill a couple milliseconds, so remember, if you add anything to your RTB when you send 0x25, be sure to add it AFTER you send the data back to bnet, cause it slows u down drasticly (As shown in my xbot compared to my buddhabot, xbot uses the 2 color, 2 text adding routine, compared to buddha which uses a modified version of groks sub, xbot gets half second logins, compared to buddha which can lag a tiny bit before login, and xbot adds like 8 things to the rtb also).
But anyways, yeah groks is bigger and better :-p
See this thread (http://forum.valhallalegends.com/?board=bot;action=display;num=1046231040).
EDIT: can't type (Shee = See)