• Welcome to Valhalla Legends Archive.
 

AppendRTB Function

Started by effect, May 19, 2004, 08:51 PM

Previous topic - Next topic

effect

Well , i wrote this a couple of weeks back , maybe some can use it , just a simple "addchat?" type function.


'Richtext box append text function
'author: effect
Public Function sAppendRTB(ByVal sText As String, ByVal sColor As String, ByVal sFontName As String, ByVal sFontSize As Integer, ByVal sUnderLined As Boolean, ByVal sBold As Boolean, ByVal sItalic As Boolean)

sTimeStamp = "[" & Format(Time, "hh:mm:ss") & "] "

With frmMain.txtOUT
   .SelLength = 0
   .SelStart = Len(.Text)
   .SelFontName = sFontName
   .SelFontSize = sFontSize
   .SelColor = vbWhite 'timestamp constant color
   .SelText = sTimeStamp 'add the timestamp without any text formatting
       If sBold = True Then
           .SelBold = True 'bold
       End If
       If sUnderLined = True Then
           .SelUnderline = True 'underlined
       End If
       If sItalic = True Then
           .SelItalic = True 'italics
       End If
    .SelColor = sColor  'text color
   .SelText = sText & vbNewLine
End With

End Function


Usage:

Call sAppendRTB(String, Color, Font, FontSize, Underlined, Bold, Italics)


Underlined , Bold and Italics are all booleans , [True/False]
Quote from: Mangix on March 22, 2005, 03:03 AM
i am an expert Stealthbot VBScript. Recognize Bitch.

Eli_1

#1
Can I suggest changing your function prototype to:

Public Function sAppendRTB( _
ByVal sText As String, _
ByVal sColor As ColorConstants, _
Optional sFontName As String = "Times New Roman", _
Optional sFontSize As Integer = 12, _
Optional sUnderLined As Boolean, _
Optional sBold As Boolean, _
Optional sItalic As Boolean)


It's just less to type everytime.

Call sAppendRTB("qwerty" & vbCrLf, vbGreen)
Call sAppendRTB("asdf" & vbCrLf, vbRed, , 14, , True

ect...

Eric

#2
I suggest using ParamArray() so you can add multiple colors and other text properties to a single line and perhaps adding the ability to choose which RichTextBox you wish to append.

Eli_1

Quote from: LoRd[nK] on May 19, 2004, 09:01 PM
I suggest using ParamArray() so you can add multiple colors and other text properties to a single line.

I'm kind of against ParamArray for an addtext function. In most cases it's great, but sometimes it becomes a lot more work.

Eric

Quote from: Eli_1 on May 19, 2004, 09:03 PM
Quote from: LoRd[nK] on May 19, 2004, 09:01 PM
I suggest using ParamArray() so you can add multiple colors and other text properties to a single line.

I'm kind of against ParamArray for an addtext function. In most cases it's great, but sometimes it becomes a lot more work.
Other than the fact that you have to remember the order in which to add the information in, it's quite a convenience.