I want to add a timestamp to my rtb along with some text in this fashion.
<timestamp> Name, SentData
Any help would be appreciated.
rtb.SelText = Format(Now, "YYYY-MM-DD HH:MM:SS") & " <" & Name & "> " & MessageText
Like that?
Doesn't vb have a built-in variable $time? Or was that QBasic? I dunno, but try that :)
Quotertb.SelText = Format(Now, "YYYY-MM-DD HH:MM:SS") & " <" & Name & "> " & MessageText
Like that?
What if I used
AddChat vbRed, Format(Now, "YYYY-MM-DD HH:MM:SS") & "SentData"
Would that work also.
?
QuoteWhat if I used AddChat vbRed, Format(Now, "YYYY-MM-DD HH:MM:SS") & "SentData"
Would that work also.
?
Depends on what you mean by "work."
That will show "SendData" stuck to the time and it also means that you're going to have to manually insert timestamp each time you call AddChat()... unless you want it that way.
In the AddChat() function, I insert the timestamp, then go on to display the inputted data.
'Grok's (of Clan [vL]) RTB colored text subprocedure with slight modifications.
Public Sub AddChat(ParamArray paElements() As Variant)
Dim i&
With frmMain.rtfChat
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = RGB(127, 127, 127)
.SelText = "[" & Format(Time, "HH:MM:SS") & "] "
.SelStart = Len(.Text)
For i = LBound(paElements) To UBound(paElements) Step 2
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = paElements(i)
.SelText = paElements(i + 1) & Left(vbCrLf, -2 * CLng((i + 1) = UBound(paElements)))
.SelStart = Len(.Text)
Next i
End With
End Sub
frmMain.rtfChat would of course be your pointer to the RTB control.
Thanks
Expanding on that, add a global boolean to toggle timestamping.
Public gShowTimestamps As Boolean
now in AddChat---
...
If gShowTimeStamps = True Then
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = Colors(COLOR_TIMESTAMP) 'array or collection of customizable colors
.SelText = "[" & Format(Time, "HH:MM:SS") & "] "
.SelStart = Len(.Text)
End If
...