SendMessage MethodSendMessage Method*
*Contents  *Index  *Topic Contents
*Previous Topic: SendInvitation Method
*Next Topic: Channels Collection Object

SendMessage Method

Sends text or data messages to the channel or members of the channel.

Syntax

object.SendMessage MessageType, Message[, RecipientNicknames][, DataMessageTag]

Parameters

objectRequired. An object expression that evaluates to a Channel object.
MessageTypeRequired. A long integer that is a combination of some of the enumMessageType enumeration values. The valid MessageType values are:
msgtNormal
msgtNotice
msgtData
msgtDataRequest
msgtDataReply
msgtWhisper
msgtData + msgtDataRaw
msgtDataRequest + msgtDataRaw
msgtAction + msgtNormal
msgtSound + msgtNormal
msgtCTCP + msgtNormal
msgtAction + msgtNotice
msgtSound + msgtNotice
msgtCTCP + msgtNotice
msgtAction + msgtWhisper
msgtSound + msgtWhisper
msgtCTCP + msgtWhisper

The msgtNotice, msgtData, msgtDataRequest, msgtDataReply, and msgtWhisper values are mutually exclusive.

The msgtData, msgtDataRequest, msgtDataReply, msgtAction, msgtSound, and msgtCTCP values are mutually exclusive.

The msgtDataRaw, msgtAction, msgtSound, and msgtCTCP values are mutually exclusive.

MessageRequired. A variant containing the actual message to send. It can be a string, a number, an array of strings, an array of numbers, or an array of variants that can be strings and numbers. The variant types allowed for those numbers are:
VT_UI1
VT_I2
VT_I4
VT_R4
VT_R8
VT_BOOL
VT_ERROR
VT_CY
VT_DATE

When sending data and the msgtDataRaw flag is not set, the control packages the Message variant into an array of bytes. An internal header is used to notify the recipient(s) that the message originates from an MsChatPr control.

When the msgtDataRaw flag is also set, the Message variant can only be a postprocessed string, a byte, an array of bytes, or an array of variants that are bytes.

A postprocessed string is a string that was modified using the regular conversion scheme, as shown in the following table.
Character    Becomes string
'\0' "\0"
'\' "\\"
'\n' "\n"
'\r' "\r"
'\t' "\t"
' ' "\b"
',' "\c"

When sending raw data, the control simply converts the Message parameter into a postprocessed string without using an internal header. This way all clients can handle the data message.

RecipientNicknamesOptional. A variant. Can be missing, an empty variant, or an empty string to send the message to the channel. Otherwise it can be a string, an array of strings, or an array of variants that are strings to send the message to designated channel members.

On IRC servers, there is no method to send a message to specific channel members, so the RecipientNicknames parameter must always be empty or missing.

On IRCX servers, the RecipientNicknames parameter can always specify one or more recipients, or it can be empty.

When msgtWhisper is used, the parameter must specify one or more recipients. The recipient list is exposed to the recipients only when using the msgtWhisper type.

DataMessageTagOptional. A variant. For IRCX servers only. This parameter is used only when sending data (that is, the msgtData, msgtDataRequest, or msgtDataReply flag is set). If sending data, this parameter must be a non-empty string. In all other cases, this parameter must be empty or missing.

Examples

1. Send a regular string to the channel:

MsChatPr1.Channels(4).SendMessage msgtNormal, "Hi there!"

2. Send a notice to the channel:

chan3.SendMessage msgtNotice, "Bye now!"

3. Send an action to the channel (CTCP action):

chanobj.SendMessage msgtAction, "is eating couscous...."

4. Send a sound to the channel (CTCP sound):

MsChatPr1.Channels.Item(2).SendMessage msgtSound, "couscous.wav Isn't that cool?"

5. Send a CTCP message to the channel:

MsChatPr1.Channels(3).SendMessage msgtCTCP, "FINGER"

6. Send text to a channel member:

chanobj.SendMessage msgtNormal, "I'm an alien spy, and U?", "SharonL"

7. Send a notice to several channel members:

Dim strRecipients(1 To 3) As String
strRecipients(1) = "ColeenS"
strRecipients(2) = "DerrickL"
strRecipients(3) = "EuniceM"
chanobj.SendMessage msgtNotice, "I'm a spy, too...", strRecipients
'or
Dim vRecipients(1 To 3) As Variant
vRecipients(1) = "ColeenS"
vRecipients(2) = "DerrickL"
vRecipients(3) = "EuniceM"
chanobj.SendMessage msgtNotice, "I'm a spy, too...", vRecipients

8. Send an action to several channel members:

Dim strRecipients(1 To 3) As String
strRecipients(1) = "ColeenS"
strRecipients(2) = "DerrickL"
strRecipients(3) = "EuniceM"
chanobj.SendMessage msgtAction, "is eating macaroni and cheese....", strRecipients
'or
Dim vRecipients(1 To 3) As Variant
vRecipients(1) = "ColeenS"
vRecipients(2) = "DerrickL"
vRecipients(3) = "EuniceM"
chanobj.SendMessage msgtAction, "is eating macaroni and cheese....", vRecipients

9. Whisper text to a channel member:

chanobj.SendMessage msgtWhisper, "I'm an alien spy, and U?", "SharonL"

10. Whisper text to channel members:

Dim strRecipients(1 To 3) As String
strRecipients(1) = "SteveL"
strRecipients(2) = "WadeR"
strRecipients(3) = "Eldon"
chanobj.SendMessage msgtWhisper, "I'm a spy, too...", strRecipients
'or
Dim vRecipients(1 To 3) As Variant
vRecipients(1) = "Charlotte"
vRecipients(2) = "Zorg"
vRecipients(3) = "Arthur"
chanobj.SendMessage msgtWhisper, "I'm a cook, too...", vRecipients

11. Send a string as data to the channel:

chanobj.SendMessage msgtData, "And a painter as well.", , "_FOO_"

12. Send a number to channel members:

Dim vRecipients(1 To 3) As Variant
vRecipients(1) = "Charlotte"
vRecipients(2) = "Zorg"
vRecipients(3) = "Arthur"
chanobj.SendMessage msgtData, 1156, vRecipients, "X"

13. Send an array of numbers to the channel:

Dim iValues(1 To 4) As Integer
iValues(1) = 10
iValues(2) = -22
iValues(3) = 123
iValues(4) = 0
chanobj.SendMessage msgtData, iValues, , "COORD"
'or 
Dim vValues(1 To 4) As Variant
vValues(1) = 10
vValues(2) = -22
vValues(3) = 123
vValues(4) = 0
chanobj.SendMessage msgtData, vValues, , "COORD"

14. Send an array of strings to a channel member:

Dim strValues(1 To 4) As String
strValues(1) = "Blue"
strValues(2) = "Green"
strValues(3) = "Red"
strValues(4) = "White"
chanobj.SendMessage msgtData, strValues, "Arthur", "COLORS"
'or 
Dim vValues(1 To 4) As Variant
vValues(1) = "Blue"
vValues(2) = "Green"
vValues(3) = "Red"
vValues(4) = "White"
chanobj.SendMessage msgtData, vValues, "Arthur", "COLORS"

15. Send an array of variants to the channel:

Dim vValues(5 To 10) As Variant
vVariant(5) = Now
vVariant(6) = "Your turn to play...."
vVariant(7) = -10
vVariant(8) = 5
vVariant(9) = -12.689
vVariant(10) = 9876582146
chanobj.SendMessage msgtData, vValues, , "TheHugeOne"

16. Send raw data to the channel:

'A postprocessed string
chanobj.SendMessage msgtData+msgtDataRaw,_
      "dhe\rotk\\nsk\0k45v\0zxa\\v", , "ProcessedString"
'One byte
Dim byt As Byte
byt = 56
chanobj.SendMessage msgtData+msgtDataRaw, byt, , "OneByte"
'An array of bytes
Dim rgBytes(1 To 3) As Byte
rgBytes(1) = 15
rgBytes(2) = 98
rgBytes(3) = 2
chanobj.SendMessage msgtData+msgtDataRaw,_
    rgBytes, , "ArrayOfBytes"
'An array of Variants that are bytes
Dim vByt(1 To 3) As Variant
vByt(1) = CByte(15)
vByt(2) = CByte(98)
vByt(3) = CByte(2)
chanobj.SendMessage msgtData+msgtDataRaw,_
      vByt, , "ArrayOfVariants"

See Also

enumMessageType, OnMessage