MSComm Control

The MSComm control provides serial communications for your application by allowing the transmission and reception of data through a serial port.

Syntax

MSComm

Remarks

The MSComm control provides the following two ways for handling communications:

•	Event-driven communications is a very powerful method for handling serial port interactions. In many situations you want to be notified the moment an event takes place, such as when a character arrives or a change occurs in the Carrier Detect (CD) or Request To Send (RTS) lines. In such cases, use the MSComm control's OnComm event to trap and handle these communications events. The OnComm event also detects and handles communications errors. For a list of all possible events and communications errors, see the CommEvent property.

•	You can also poll for events and errors by checking the value of the CommEvent property after each critical function of your program. This may be preferable if your application is small and self-contained. For example, if you are writing a simple phone dialer, it may not make sense to generate an event after receiving every character, because the only characters you plan to receive are the OK response from the modem.

Each MSComm control you use corresponds to one serial port. If you need to access more than one serial port in your application, you must use more than one MSComm control. The port address and interrupt address can be changed from the Windows Control Panel.

Although the MSComm control has many important properties, there are a few that you should be familiar with first.

Properties	Description
CommPort	Sets and returns the communications port number.
Settings	Sets and returns the baud rate, parity, data bits, and stop bits as a string.
PortOpen	Sets and returns the state of a communications port. Also opens and closes a port.
Input	Returns and removes characters from the receive buffer.
Output	Writes a string of characters to the transmit buffer.


MSComm Control Example

The following simple example shows basic serial communications using a modem:

Private Sub Form_Load ()

' Buffer to hold input string

Dim Instring As String

' Use COM1.

MSComm1.CommPort = 1

' 9600 baud, no parity, 8 data, and 1 stop bit.

MSComm1.Settings = "9600,N,8,1"

' Tell the control to read entire buffer when Input

' is used.

MSComm1.InputLen = 0

' Open the port.

MSComm1.PortOpen = True

' Send the attention command to the modem.

MSComm1.Output = "AT" + Chr$(13)

' Wait for data to come back to the serial port.

Do

DoEvents

Loop Until MSComm1.InBufferCount >= 2

' Read the "OK" response data in the serial port.

Instring = MSComm1.Input

' Close the serial port.

MSComm1.PortOpen = False

End Sub

Note   The MSComm control can use polling or an event-driven method to retrieve data from the port. This simple example uses the polling method. For an example of the event-driven method, see help for the OnComm event.


Break Property

Sets or clears the break signal state. This property is not available at design time.

Syntax

object.Break [ = value]

The Break property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A Boolean expression specifying whether the break signal state is set, as described in Settings.
Settings

The settings for value are:

Setting	Description
True	Sets the break signal state.
False	Clears the break signal state.
Remarks

When set to True, the Break property sends a break signal. The break signal suspends character transmission and places the transmission line in a break state until you set the Break property to False.

Typically, you set the break state for a short interval of time, and only if the device with which you are communicating requires that a break signal be set.

Data Type

Boolean


Break Property Example

The following example shows how to send a break signal for a tenth of a second:

' Set the Break condition.

MSComm1.Break = True

' Set duration to 1/10 second.

Duration! = Timer + .1

' Wait for the duration to pass.

Do Until Timer > Duration!

Dummy = DoEvents()

Loop

' Clear the Break condition.

MSComm1.Break = False


CDHolding Property

Determines whether the carrier is present by querying the state of the Carrier Detect (CD) line. Carrier Detect is a signal sent from a modem to the attached computer to indicate that the modem is online. This property is not available at design time and is read-only at run time.

Syntax

object.CDHolding

The CDHolding property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
Settings

The settings for the CDHolding property are:

Setting	Description
True	Carrier Detect line is high
False	Carrier Detect line is low
Remarks

When the Carrier Detect line is high (CDHolding = True) and times out, the MSComm control sets the CommEvent property to comEventCDTO (Carrier Detect Timeout Error), and generates the OnComm event.

Note   It is especially important to trap a loss of the carrier in a host application, such as a bulletin board, because the caller can hang up (drop the carrier) at any time.

The Carrier Detect is also known as the Receive Line Signal Detect (RLSD).

Data Type

Boolean


CommEvent Property

Returns the most recent communication event or error. This property is not available at design time and is read-only at run time.

Syntax

object.CommEvent

The CommEvent property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
Remarks

Although the OnComm event is generated whenever a communication error or event occurs, the CommEvent property holds the numeric code for that error or event. To determine the actual error or event that caused the OnComm event, you must reference the CommEvent property.

The CommEvent property returns one of the following values for communication errors or events. These constants can also be found in the Object Library for this control.

Communication errors include the following settings:

Constant	Value	Description
comEventBreak	1001	A Break signal was received.
comEventCTSTO	1002	Clear To Send Timeout. The Clear To Send line was low for the system specified amount of time while trying to transmit a character.
comEventDSRTO	1003	Data Set Ready Timeout. The Data Set Ready line was low for the system specified amount of time while trying to transmit a character.
ComEventFrame	1004	Framing Error. The hardware detected a framing error.
ComEventOverrun	1006	Port Overrun. A character was not read from the hardware before the next character arrived and was lost.
ComEventCDTO	1007	Carrier Detect Timeout. The Carrier Detect line was low for the system specified amount of time while trying to transmit a character. Carrier Detect is also known as the Receive Line Signal Detect (RLSD).
ComEventRxOver	1008	Receive Buffer Overflow. There is no room in the receive buffer.
ComEventRxParity	1009	Parity Error. The hardware detected a parity error.
ComEventTxFull	1010	Transmit Buffer Full. The transmit buffer was full while trying to queue a character.
ComEventDCB	1011	Unexpected error retrieving Device Control Block (DCB) for the port.
Communications events include the following settings:

Constant	Value	Description
comEvSend	1	There are fewer than Sthreshold number of characters in the transmit buffer.
ComEvReceive	2	Received Rthreshold number of characters. This event is generated continuously until you use the Input property to remove the data from the receive buffer.
ComEvCTS	3	Change in Clear To Send line.
comEvDSR	4	Change in Data Set Ready line. This event is only fired when DSR changes from 1 to 0.
comEvCD	5	Change in Carrier Detect line.
comEvRing	6	Ring detected. Some UARTs (universal asynchronous receiver-transmitters) may not support this event.
comEvEOF	7	End Of File (ASCII character 26) character received.
Data Type

Integer


CommID Property

Returns a handle that identifies the communications device. This property is not available at design time and is read-only at run time.

Syntax

object.CommID

The CommID property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
Remarks

This is the same value that's returned by the Windows API CreateFile function. Use this value when calling any communications routines in the Windows API.

Data Type

Long


CommPort Property

Sets and returns the communications port number.

Syntax

object.CommPort[ = value ]

The CommPort property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A integer value specifying the port number.
Remarks

You can set value to any number between 1 and 16 at design time (the default is 1). However, the MSComm control generates error 68 (Device unavailable) if the port does not exist when you attempt to open it with the PortOpen property.

Warning   You must set the CommPort property before opening the port.

Data Type

Integer


CTSHolding Property

Determines whether you can send data by querying the state of the Clear To Send (CTS) line. Typically, the Clear To Send signal is sent from a modem to the attached computer to indicate that transmission can proceed. This property is not available at design time and is read-only at run time.

Syntax

object.CTSHolding

The CTSHolding property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
The following table lists the CTSHolding property settings for the MSComm control.

Setting	Description
True	Clear To Send line high.
False	Clear To Send line low.
Remarks

When the Clear To Send line is low (CTSHolding = False) and times out, the MSComm control sets the CommEvent property to comEventCTSTO (Clear To Send Timeout) and invokes the OnComm event.

The Clear To Send line is used in RTS/CTS (Request To Send/Clear To Send) hardware handshaking. The CTSHolding property gives you a way to manually poll the Clear To Send line if you need to determine its state.

For more information   on handshaking protocols, see the Handshaking property.

Data Type

Boolean


DSRHolding Property

Determines the state of the Data Set Ready (DSR) line. Typically, the Data Set Ready signal is sent by a modem to its attached computer to indicate that it is ready to operate. This property is not available at design time and is read-only at run time.

Syntax

object.DSRHolding

The object placeholder represents an object expression that evaluates to an object in the Applies To list.

The DSRHolding property returns the following values:

Value	Description
True	Data Set Ready line high
False	Data Set Ready line low
Remarks

When the Data Set Ready line is high (DSRHolding = True) and has timed out, the MSComm control sets the CommEvent property to comEventDSRTO (Data Set Ready Timeout) and invokes the OnComm event.

This property is useful when writing a Data Set Ready/Data Terminal Ready handshaking routine for a Data Terminal Equipment (DTE) machine.

Data Type

Boolean


DTREnable Property

Determines whether to enable the Data Terminal Ready (DTR) line during communications. Typically, the Data Terminal Ready signal is sent by a computer to its modem to indicate that the computer is ready to accept incoming transmission.

Syntax

object.DTREnable[ = value ]

The DTREnable property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
Value	A Boolean expression specifying whether to enable the Data Terminal Ready (DTR) line, as described in Settings.
Settings

The settings for value are:

Setting	Description
True	Enable the Data Terminal Ready line.
False	(Default) Disable the Data Terminal Ready line.
Remarks

When DTREnable is set to True, the Data Terminal Ready line is set to high (on) when the port is opened, and low (off) when the port is closed. When DTREnable is set to False, the Data Terminal Ready always remains low.

Note   In most cases, setting the Data Terminal Ready line to low hangs up the telephone.

Data Type

Boolean


Handshaking Property

Sets and returns the hardware handshaking protocol.

Syntax

object.Handshaking [ = value ]

The Handshaking property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the handshaking protocol, as described in Settings.
Settings

The settings for value are:

Setting	Value	Description
comNone	0	(Default) No handshaking.
comXOnXOff	1	XON/XOFF handshaking.
comRTS	2	RTS/CTS (Request To Send/Clear To Send) handshaking.
comRTSXOnXOff	3	Both Request To Send and XON/XOFF handshaking.
Remarks

Handshaking refers to the internal communications protocol by which data is transferred from the hardware port to the receive buffer. When a character of data arrives at the serial port, the communications device has to move it into the receive buffer so that your program can read it. If there is no receive buffer and your program is expected to read every character directly from the hardware, you will probably lose data because the characters can arrive very quickly.

A handshaking protocol insures data is not lost due to a buffer overrun, where data arrives at the port too quickly for the communications device to move the data into the receive buffer.

Data Type

Integer


InBufferCount Property

Returns the number of characters waiting in the receive buffer. This property is not available at design time.

Syntax

object.InBufferCount[ = value ]

The InBufferCount property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the number of characters waiting in the receive buffer.
Remarks

InBufferCount refers to the number of characters that have been received by the modem and are waiting in the receive buffer for you to take them out. You can clear the receive buffer by setting the InBufferCount property to 0.

Note   Do not confuse this property with the InBufferSize property. The InBufferSize property reflects the total size of the receive buffer.

Data Type

Integer


InBufferSize Property

Sets and returns the size of the receive buffer in bytes.

Syntax

object.InBufferSize[ = value ]

The InBufferSize property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the size of the receive buffer in bytes.
Remarks

InBufferSize refers to the total size of the receive buffer. The default size is 1024 bytes. Do not confuse this property with the InBufferCount property which reflects the number of characters currently waiting in the receive buffer.

Note   Note that the larger you make the receive buffer, the less memory you have available to your application. However, if your buffer is too small, it runs the risk of overflowing unless handshaking is used. As a general rule, start with a buffer size of 1024 bytes. If an overflow error occurs, increase the buffer size to handle your application's transmission rate.

Data Type

Integer


Input Property

Returns and removes a stream of data from the receive buffer. This property is not available at design time and is read-only at run time.

Syntax

object.Input

The Input property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
Remarks

The InputLen property determines the number of characters that are read by the Input property. Setting InputLen to 0 causes the Input property to read the entire contents of the receive buffer.

The InputMode property determines the type of data that is retrieved with the Input property. If InputMode is set to comInputModeText then the Input property returns text data in a Variant. If InputMode is comInputModeBinary then the Input property returns binary data in an array of bytes in a Variant.

Data Type

Variant


Input Property Example

This example shows how to retrieve data from the receive buffer:

Private Sub Command1_Click()

Dim InString as String

' Retrieve all available data.

MSComm1.InputLen = 0

' Check for data.

If MSComm1.InBufferCount Then

' Read data.

InString = MSComm1.Input

End If

End Sub


InputLen Property

Sets and returns the number of characters the Input property reads from the receive buffer.

Syntax

object.InputLen [ = value ]

The InputLen property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the number of characters the Input property reads from the receive buffer.
Remarks

The default value for the InputLen property is 0. Setting InputLen to 0 causes the MSComm control to read the entire contents of the receive buffer when Input is used.

If InputLen characters are not available in the receive buffer, the Input property returns a zero-length string (""). The user can optionally check the InBufferCount property to determine if the required number of characters are present before using Input.

This property is useful when reading data from a machine whose output is formatted in fixed-length blocks of data.

Data Type

Integer


InputLen Property Example

This example shows how to read 10 characters of data:

Private Command1_Click()

Dim CommData as String

' Specify a 10 character block of data.

MSComm1.InputLen = 10

' Read data.

CommData = MSComm1.Input

End Sub


NullDiscard Property, MSComm Control
NullDiscard Property

Determines whether null characters are transferred from the port to the receive buffer.

Syntax

object.NullDiscard [ = value ]

The NullDiscard property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An boolean expression specifying whether null characters are transferred from the port to the receive buffer, as described in Settings
Settings

The settings for value are:

Setting	Description
True	Null characters are not transferred from the port to the receive buffer.
False	(Default) Null characters are transferred from the port to the receive buffer.
Remarks

A null character is defined as ASCII character 0, Chr$(0).

Data Type

Boolean


OutBufferCount Property

Returns the number of characters waiting in the transmit buffer. You can also use it to clear the transmit buffer. This property is not available at design time.

Syntax

object.OutBufferCount [ = value ]

The OutBufferCount property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the number of characters waiting in the transmit buffer.
Remarks

You can clear the transmit buffer by setting the OutBufferCount property to 0.

Note   Do not confuse the OutBufferCount property with the OutBufferSize property which reflects the total size of the transmit buffer.

Data Type

Integer


OutBufferSize Property

Sets and returns the size, in bytes, of the transmit buffer.

Syntax

object.OutBufferSize [ = object ]

The OutBufferSize property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the size of the transmit buffer.
Remarks

OutBufferSize refers to the total size of the transmit buffer. The default size is 512 bytes. Do not confuse this property with the OutBufferCount which reflects the number of bytes currently waiting in the transmit buffer.

Note   The larger you make the transmit buffer, the less memory you have available to your application. However, if your buffer is too small, you run the risk of overflowing unless you use handshaking. As a general rule, start with a buffer size of 512 bytes. If an overflow error occurs, increase the buffer size to handle your application's transmission rate.

Data Type

Integer


Output Property

Writes a stream of data to the transmit buffer. This property is not available at design time and is write-only at run time.

Syntax

object.Output [ = value ]

The Output property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A string of characters to write to the transmit buffer.
Remarks

The Output property can transmit text data or binary data. To send text data using the Output property, you must specify a Variant that contains a string. To send binary data, you must pass a Variant which contains a byte array to the Output property.

Normally, if you you are sending an ANSI string to an application, you can send it as text data. If you have data that contains embedded control characters, Null characters, etc., then you will want to pass it as binary data.

Data Type

Variant


Output Property Example, MSComm Control
Output Property Example

The following example shows how to send every character the user types to the serial port:

Private Sub Form_KeyPress (KeyAscii As Integer)

Dim Buffer as Variant

' Set and open port

MSComm1.CommPort = 1

MSComm1.PortOpen = True

Buffer = Chr$(KeyAscii)

MSComm1.Output = Buffer

End Sub


ParityReplace Property

Sets and returns the character that replaces an invalid character in the data stream when a parity error occurs.

Syntax

object.ParityReplace [ = value ]

The ParityReplace property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A string expression representing a character, as described in Remarks.
Remarks

The parity bit refers to a bit that is transmitted along with a specified number of data bits to provide a small amount of error checking. When you use a parity bit, the MSComm control adds up all the bits that are set (having a value of 1) in the data and tests the sum as being odd or even (according to the parity setting used when the port was opened).

By default, the control uses a question mark (?) character for replacing invalid characters. Setting ParityReplace to an empty string ("") disables replacement of the character where the parity error occurs. The OnComm event is still fired and the CommEvent property is set to comEventRXParity.

The ParityReplace character is used in a byte-oriented operation, and must be a single-byte character. You can specify any ANSI character code with a value from 0 to 255.

Data Type

String


PortOpen Property

Sets and returns the state of the communications port (open or closed). Not available at design time.

Syntax

object.PortOpen [ = value ]

The PortOpen property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A boolean expression specifying the state of the communications port.
Settings

The settings for value are:

Setting	Description
True	Port is opened
False	Port is closed
Remarks

Setting the PortOpen property to True opens the port. Setting it to False closes the port and clears the receive and transmit buffers. The MSComm control automatically closes the serial port when your application is terminated.

Make sure the CommPort property is set to a valid port number before opening the port. If the CommPort property is set to an invalid port number when you try to open the port, the MSComm control generates error 68 (Device unavailable).

In addition, your serial port device must support the current values in the Settings property. If the Settings property contains communications settings that your hardware does not support, your hardware may not work correctly.

If either the DTREnable or the RTSEnable properties is set to True before the port is opened, the properties are set to False when the port is closed. Otherwise, the DTR and RTS lines remain in their previous state.

Data Type

Boolean


PortOpen Property Example

The following example opens communications port number 1 at 9600 baud with no parity checking, 8 data bits, and 1 stop bit:

MSComm1.Settings = "9600,n,8,1"

MSComm1.CommPort = 1

MSComm1.PortOpen = True


RThreshold Property

Sets and returns the number of characters to receive before the MSComm control sets the CommEvent property to comEvReceive and generates the OnComm event.

Syntax

object.Rthreshold [ = value ]

The Rthreshold property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression specifying the number of characters to receive before generating the OnComm event.
Remarks

Setting the RThreshold property to 0 (the default) disables generating the OnComm event when characters are received.

Setting RThreshold to 1, for example, causes the MSComm control to generate the OnComm event every time a single character is placed in the receive buffer.

Data Type

Integer


RTSEnable Property

Determines whether to enable the Request To Send (RTS) line. Typically, the Request To Send signal that requests permission to transmit data is sent from a computer to its attached modem.

Syntax

object.RTSEnable[ = value ]

The RTSEnable property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An boolean expression specifying whether the Request To Send (RTS) line is enabled, as described in Settings.
Settings

The settings for value are:

Setting	Description
True	Enables the Request To Send line.
False	(Default) Disables the Request To Send line.
Remarks

When RTSEnable is set to True, the Request To Send line is set to high (on) when the port is opened, and low (off) when the port is closed.

The Request To Send line is used in RTS/CTS hardware handshaking. The RTSEnable property allows you to manually poll the Request To Send line if you need to determine its state.

For more information   on handshaking protocols, see the Handshaking property.

Data Type

Boolean


Settings Property

Sets and returns the baud rate, parity, data bit, and stop bit parameters.

Syntax

object.Settings [ = value ]

The Settings property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An string expression representing the communications port settings, as described below.
Remarks

If value is not valid when the port is opened, the MSComm control generates error 380 (Invalid property value).

Value is composed of four settings and has the following format:

"BBBB,P,D,S"

Where BBBB is the baud rate, P is the parity, D is the number of data bits, and S is the number of stop bits. The default value of value is:

"9600,N,8,1"

The following table lists the valid baud rates.

Setting

110

300

600

1200

2400

9600 (Default)

14400

19200

28800

38400 (reserved)

56000 (reserved)

128000 (reserved)

256000 (reserved)

The following table describes the valid parity values.

Setting	Description
E	Even
M	Mark
N	(Default)
None
O	Odd
S	Space
The following table lists the valid data bit values.

Setting

4

5

6

7

8

(Default)

The following table lists the valid stop bit values.

Setting
1	(Default)
1.5
2
Data Type

String


Settings Example

The following example sets the control's port to communicate at 9600 baud with no parity checking, 8 data bits, and 1 stop bit:

MSComm1.Settings = "9600,N,8,1"


SThreshold Property

Sets and returns the minimum number of characters allowable in the transmit buffer before the MSComm control sets the CommEvent property to comEvSend and generates the OnComm event.

Syntax

object.SThreshold [ = value ]

The SThreshold property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	An integer expression representing the minimum number of characters in the transmit buffer before the OnComm event is generated.
Remarks

Setting the SThreshold property to 0 (the default) disables generating the OnComm event for data transmission events. Setting the SThreshold property to 1 causes the MSComm control to generate the OnComm event when the transmit buffer is completely empty.

If the number of characters in the transmit buffer is less than value, the CommEvent property is set to comEvSend, and the OnComm event is generated. The comEvSend event is only fired once, when the number of characters crosses the SThreshold. For example, if SThreshold equals five, the comEvSend event occurs only when the number of characters drops from five to four in the output queue. If there are never more than SThreshold characters in the output queue, the event is never fired.

Data Type

Integer


OnComm Event

The OnComm event is generated whenever the value of the CommEvent property changes, indicating that either a communication event or an error occurred.

Syntax

Private Sub object_OnComm ()

The OnComm event syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
Remarks

The CommEvent property contains the numeric code of the actual error or event that generated the OnComm event. Note that setting the RThreshold or SThreshold properties to 0 disables trapping for the comEvReceive and comEvSend events, respectively.


OnComm Event Example

The following example shows how to handle communications errors and events. You can insert code after each related Case statement, to handle a particular error or event.

Private Sub MSComm_OnComm ()

Select Case MSComm1.CommEvent

' Handle each event or error by placing

' code below each case statement

' Errors

Case comEventBreak	' A Break was received.

Case comEventCDTO	' CD (RLSD) Timeout.

Case comEventCTSTO	' CTS Timeout.

Case comEventDSRTO	' DSR Timeout.

Case comEventFrame	' Framing Error

Case comEventOverrun	' Data Lost.

Case comEventRxOver	' Receive buffer overflow.

Case comEventRxParity	' Parity Error.

Case comEventTxFull	' Transmit buffer full.

Case comEventDCB	' Unexpected error retrieving DCB]

' Events

Case comEvCD	' Change in the CD line.

Case comEvCTS	' Change in the CTS line.

Case comEvDSR	' Change in the DSR line.

Case comEvRing	' Change in the Ring Indicator.

Case comEvReceive	' Received RThreshold # of
' chars.

Case comEvSend	' There are SThreshold number of
' characters in the transmit
' buffer.

Case comEvEof	' An EOF charater was found in 	' the input stream

End Select

End Sub


MSComm Control Constants

Handshake Constants

Constant	Value	Description
comNone	0	No handshaking.
comXonXoff	1	XOn/XOff handshaking.
comRTS	2	Request-to-send/clear-to-send handshaking.
comRTSXOnXOff	3	Both request-to-send and XOn/XOff handshaking.
OnComm Constants

Constant	Value	Description
comEvSend	1	Send event.
comEvReceive	2	Receive event.
comEvCTS	3	Change in clear-to-send line.
comEvDSR	4	Change in data-set ready line.
comEvCD	5	Change in carrier detect line.
comEvRing	6	Ring detect.
comEvEOF	7	End of file.
Error Constants

Constant	Value	Description
comEventBreak	1001	Break signal received
comEventCTSTO	1002	Clear-to-send timeout
comEventDSRTO	1003	Data-set ready timeout
comEventFrame	1004	Framing error
comEventOverrun	1006	Port overrun
comEventCDTO	1007	Carrier detect timeout
comEventRxOver	1008	Receive buffer overflow
comEventRxParity	1009	Parity error
comEventTxFull	1010	Transmit buffer full
comEventDCB	1011	Unexpected error retrieving Device Control Block (DCB) for the port
InputMode Constants

Constant	Value	Description
comInputModeText	0	(Default) Data is retrieved through the Input property as text.
comInputModeBinary	1	Data is retrieved through the Input property as binary data.


Error Messages

The following table lists the trappable errors for the MSComm control.

Error Number	Message Explanation
8000	Operation not valid while the port is opened
8001	Timeout value must be greater than zero
8002	Invalid Port Number
8003	Property available only at run time
8004	Property is read only at runtime
8005	Port already open
8006	The device identifier is invalid or unsupported
8007	The device's baud rate is unsupported
8008	The specified byte size is invalid
8009	The default parameters are in error
8010	The hardware is not available (locked by another device)
8011	The function cannot allocate the queues
8012	The device is not open
8013	The device is already open
8014	Could not enable comm notification
8015	Could not set comm state
8016	Could not set comm event mask
8018	Operation valid only when the port is open
8019	Device busy
8020	Error reading comm device


EOFEnable Property

The EOFEnable property determines if the MSComm control looks for End Of File (EOF) characters during input. If an EOF character is found, the input will stop and the OnComm event will fire with the CommEvent property set to comEvEOF.

Syntax

object.EOFEnable [ = value ]

The EOFEnable property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A boolean expression that determines whether the OnComm event is fired when an EOF character is found, as described in Settings.
Settings

The settings for value are:

Setting	Description
True	The OnComm event is fired when an EOF character is found.
False	(Default) The OnComm event isn't fired when an EOF character is found.
Remarks

When EOFEnable property is set to False, the control will not scan the input stream for EOF characters.


InputMode Property

Sets or returns the type of data retrieved by the Input property.

Syntax

object.InputMode [ = value ]

The InputMode property syntax has these parts:

Part	Description
object	An object expression that evaluates to an object in the Applies To list.
value	A value or constant that specifies the input mode, as described in Settings.
Settings

The settings for value are:

Constant	Value	Description
comInputModeText	0	(Default) Data is retrieved through the Input property as text.
comInputModeBinary	1	Data is retrieved through the Input property as binary data.
Remarks

The InputMode property determines how data will be retrieved through the Input property. The data will either be retrieved as string or as binary data in a byte array.

Use comInputModeText for data that uses the ANSI character set. Use comInputModeBinary for all other data such as data that has embedded control characters, Nulls, etc.


InputMode Property Example

This example reads 10 bytes of binary data from the communications port and assigns it to a byte array.

Private Sub Command1_Click()

Dim Buffer as Variant

Dim Arr() as Byte

' Set and open port

MSComm1.CommPort = 1

MSComm1.PortOpen = True

' Set InputMode to read binary data

MSComm1.InputMode = comInputModeBinary

' Wait until 10 bytes are in the input buffer

Do Until MSComm1.InBufferCount < 10

    DoEvents

Loop

' Store binary data in buffer

Buffer = MSComm1.Input

' Assign to byte array for processing

Arr = Buffer

End Sub


Change Event (placeholder)


Click Event (placeholder)


DblClick Event (placeholder)


DragDrop Event (placeholder)


DragOver Event (placeholder)


KeyDown Event (placeholder)


KeyPress Event (placeholder)


KeyUp Event (placeholder)


MouseDown Event (placeholder)


MouseMove Event (placeholder)


MouseUp Event (placeholder)


OLECompleteDragEvent (placeholder)


OLEDragDrop Event (placeholder)


OLEDragOver Event (placeholder)


OLEGiveFeedback Event (placeholder)


OLESetData Event (placeholder)


OLEStartDrag Event (placeholder)


Refresh Method (placeholder)


OLEDrag Method (placeholder)


Appearance Property (placeholder)


BackColor Property (placeholder)


Caption Property (placeholder)


Enabled Property (placeholder)


Font Property (placeholder)


ForeColor Property (placeholder)


IntegralHeight Property (placeholder)


Locked Property (placeholder)


MouseIcon Property (placeholder)


MousePointer Property (placeholder)


OLEDragMode Property (placeholder)


OLEDropMode Property (placeholder)


SelLength Property (placeholder)


SelStart Property (placeholder)


SelText Property (placeholder)


Style Property (placeholder)


Text Property (placeholder)


Keyword Not Found

The keyword you've selected can't be found in Visual Basic Help. It's possible that:

•	The keyword is misspelled

•	You selected too much or too little text

•	You asked for help on a word that is not a valid Visual Basic keyword.

The easiest way to get help on a specific keyword is to position the insertion point anywhere within the keyword you want help on and press F1. You do not need to select the keyword. In fact, if you select only a portion of the keyword, or more than a single word, Help will not find what you're looking for.

To use the built-in Help search dialog box, press the Help Topics button on the toolbar.

One option to possibly find what you're looking for is to view the ReadMe file that comes with Visual Basic. This document contains information regarding last-minute changes, additions, and deletions that did not make it into the final documentation.


Left, Top Properties (Placeholder)


Height, Width Properties (Placeholder)


Tag Property (Placeholder)


ToolTipText Property (Placeholder)


Count Property (Placeholder)


Item Method (Placeholder)


Hwnd Property (Placeholder)


TabStop Property (Placeholder)


Visible Property (Placeholder)


Picture Property (placeholder)


Max, Min Properties (placeholder)


Add Method (placeholder)


Clear Method (placeholder)


Container Property (placeholder)


Controls Collection (placeholder)


Copies Property (placeholder)


DataBinding Object (placeholder)


DataBindings Collection (placeholder)


Filename Property (placeholder)


FontBold, FontItalic, FontStrikeThru Properties (placeholder)


FontName Property (placeholder)


FontSize Property (placeholder)


GetData Method (placeholder)


GetFormat Method (placeholder)


HelpFile Property (placeholder)


Item Property (placeholder)


Remove Method (placeholder)


SetData Method (placeholder)


Align Property (placeholder)


DragIcon Property (placeholder)


DragMode Property (placeholder)


HelpContextID Property (placeholder)


TabIndex Property (placeholder)


Alignment Constants (placeholder)


Border Property Constants (placeholder)


BorderStyle Constants (placeholder)


BorderStyle Property (ActiveX Controls) (placeholder)


Clear Method (ActiveX Controls) (placeholder)


Clipboard Object Constants (placeholder)


Color Constants (placeholder)


CommonDialog Control Constants (placeholder)


CommonDialog Error Constants (placeholder)


Control Constants (placeholder)


DataBindings Property (placeholder)


DDE Constants (placeholder)


Drag-and-Drop Constants (placeholder)


Drawing Constants (placeholder)


FetchVerbs Method (placeholder)


Form Constants (placeholder)


Graphics Constants (placeholder)


Grid Control Constants (placeholder)


Help Constants (placeholder)


HideSelection Property (ActiveX Controls) (placeholder)


HideSelection Property (placeholder)


Image Property (ActiveX Controls) (placeholder)


ImageList Property (ActiveX Controls) (placeholder)


Index Property (ActiveX Controls) (placeholder)


Index Property (placeholder)


Key Code Constants (placeholder)


Key Property (ActiveX Controls) (placeholder)


Menu Accelerator Constants (placeholder)


Menu Control Constants (placeholder)


Miscellaneous Constants (placeholder)


MousePointer Constants (placeholder)


OLE Container Control Constants (placeholder)


Picture Object Constants (placeholder)


Printer Object Constants (placeholder)


RasterOp Constants (placeholder)


Remove Method (ActiveX Controls) (placeholder)


ShowInTaskbar Property (placeholder)


ShowTips Property (ActiveX Controls) (placeholder)


ShowWhatsThis Method (placeholder)


Text Property (ActiveX Controls) (placeholder)


Value Property (ActiveX Controls) (placeholder)


Variant Type Constants (placeholder)


Visual Basic Constants (placeholder)


WhatsThisButton Property (placeholder)


WhatsThisHelp Property (placeholder)


WhatsThisHelpID Property (placeholder)


WhatsThisMode Method (placeholder)


Windows 95 Control Constants (placeholder)


ColIsVisible Property (placeholder)


ColPos Property (placeholder)


DataObject Object (placeholder)


DataObjectFiles Collection (placeholder)


DataSource Property (placeholder)


Drag Method (placeholder)


DrawMode Property (placeholder)


FixedAlignment Property (placeholder)


GotFocus Event (placeholder)


GridLineWidth Property (placeholder)


Index Property (Control Array) (placeholder)


LostFocus Event (placeholder)


Move Method (placeholder)


Name Property (placeholder)


Object Property (placeholder)


Parent Property (placeholder)


RowColChange Event (placeholder)


RowIsVisible Property (placeholder)


RowPos Property (placeholder)


SetFocus Method (placeholder)


ZOrder Method (placeholder)


Files Method (placeholder)


Connect Event (placeholder)


HScrollSmallChange, VScrollSmallChange Properties (placeholder)


MinHeight, MinWidth Properties (placeholder)


Property Pages Dialog Box (placeholder)


RemoteHost Property (placeholder)


RemotePort Property (placeholder)


ViewportHeight, ViewportLeft, ViewportTop, ViewportWidth Properties (placeholder)


Resync Method (Remote Data) (placeholder)


ContainedVBControls Collection (placeholder)


Member Object (placeholder)


Members Collection (placeholder)


VBComponentsEvents Object (placeholder)


VBProjectsEvents Object (placeholder)


Files Property (placeholder)


Alignment Property (placeholder)


AboutBox Method (placeholder)


Col, Row Properties (placeholder)


RowHeight Property (placeholder)


Scroll Event (placeholder)


ScrollBars Property (placeholder)


SelEndCol, SelStartCol, SelEndRow, SelStartRow Properties (placeholder)


ScrollBars Property (placeholder)


Appearance Property (ActiveX Controls) (placeholder)


BackColor, ForeColor Properties (ActiveX Controls) (placeholder)


BorderStyle Constants (ActiveX Controls) (placeholder)


Caption Property (ActiveX Controls) (placeholder)


Change Event (ActiveX Controls) (placeholder)


Clear Method (ActiveX Controls) (placeholder)


Click Event (ActiveX Controls) (placeholder)


Clipboard Object Constants (ActiveX Controls) (placeholder)


Count Property (ActiveX Controls) (placeholder)


DataObject Object (ActiveX Controls) (placeholder)


DataObjectFiles Collection (ActiveX Controls) (placeholder)


DataSource Property (ActiveX Controls) (placeholder)


DblClick Event (ActiveX Controls) (placeholder)


Drag-and-Drop Constants (ActiveX Controls) (placeholder)


Enabled Property (ActiveX Controls) (placeholder)


FetchVerbs Method (ActiveX Controls) (placeholder)


Files Method (ActiveX Controls) (placeholders)


Font Property (ActiveX Controls) (placeholder)


FontName Property (ActiveX Controls) (placeholder)


FontSize Property (ActiveX placeholder)


GetData Method (ActiveX Controls) (placeholder)


GetFormat Method (ActiveX Controls) (placeholder)


HideSelection Property (ActiveX Controls) (complaceholder)


hWnd Property (ActiveX Controls) (placeholder)


Item Method (ActiveX Controls) (placeholder)


Key Code Constants (ActiveX Controls) (placeholder)


Key Property (ActiveX Controls) (complaceholder)


KeyDown, KeyUp Events (ActiveX Controls) (placeholder)


KeyPress Event (ActiveX Controls) (placeholder)


Max, Min Properties (ActiveX Controls) (placeholder)


MouseDown, MouseUp Events (ActiveX Controls) (placeholder)


MouseIcon Property (ActiveX Controls) (placeholder)


MouseMove Event (ActiveX Controls) (placeholder)


MousePointer Constants (ActiveX Controls) (placeholder)


MousePointer Property (ActiveX Controls) (placeholder


OLECompleteDrag Event (ActiveX Controls) (placeholder)


OLEDrag Method (ActiveX Controls) (placeholder)


OLEDragDrop Event (ActiveX Controls) (placeholder)


OLEDragMode Property (ActiveX Controls) (placeholder)


OLEDragOver Event (ActiveX Controls) (placeholder)


OLEDropMode Property (ActiveX Controls) (placeholder)


OLEGiveFeedback Event (ActiveX Controls) (placeholder)


OLESetData Event (ActiveX Controls) (placeholder)


OLEStartDrag Event (ActiveX Controls) (placeholder)


Picture Property (ActiveX Controls) (placeholder)


Property Pages Dialog Box (ActiveX Controls) (placeholder)


RemoteHost Property (ActiveX Controls) (placeholder)


RemotePort Property (ActiveX Controls) (placeholder)


SelLength, SelStart, SelText Properties (ActiveX Controls) (placeholder)


SetData Method (ActiveX Controls) (placeholder)


ShowTips Property (ActiveX Controls) (complaceholder)


Text Property (ActiveX Controls) (complaceholder)


Value Property (ActiveX Controls) (complaceholder)


hDC Property (ActiveX Controls) (complaceholder)


Height, Width Properties (ActiveX Controls) (complaceholder)


Index Property (ActiveX Controls) (complaceholder)


Left, Top Properties (ActiveX Controls) (complaceholder)


Tag Property (ActiveX Controls) (complaceholder)


Visible Property (ActiveX Controls) (complaceholder)


Remove Method (ActiveX Controls) (complaceholder)


Object Property (ActiveX Controls) (placeholder)


Property Pages (ActiveX controls) (placeholder)


No fonts exist (Error 24574) (Common Dialog Control) (complaceholder)


Help Contents placeholder


BorderStyle Property (ActiveX Controls) (placeholder)


RightToLeft Property (ActiveX Controls) (placeholder)


Refresh Method (ActiveX Controls) (placeholder)