Today is...
Thursday, May 24, 2018
Welcome to, the global online
community of automation professionals.
Featured Video...
Featured Video
Watch an animation of a conveyor stacking operation demonstrating the use of a move on a gear command.
Our Advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive
serial port comunication using visual basic
how can i use visual basic codes to read input from the 1st serial port...

hi there hope someone can help me here..!!!

im doing a new project involving two serial ports of the computer. firstly, i have interfaced the 1st serial port to a 8051 microcontroller to get data from the microcontroller.

the second serial port is connected to a nokia 30 gsm connectivity terminal (it can be a gsm modem or a gsm phone).

My question here is how can i use visual basic codes to read input from the 1st serial port (which is the microcontroller) and when there is a specific input, this visual basic should send data (in this case a sms ) to the gsm phone through the 2nd serial port. This sms should be sent automatically when there is an input from the 1st serial port.

please if anyone can help me, send me the codes or any information.

your help is much appreciated..!!!

my mail add:

The easiest way to access COM ports in Visual Basic 6 is by placing the Microsoft Comm control on a form, and writing code to read and write each serial port. There are plenty of examples on the web of using the Microsoft Comm control to send and recieve data from a serial port. You will need one Microsoft Comm control on your form per serial ports you wish to use.

Example of an infinite loop that takes data from one port and echos it onto another -

Dim sInput as String
While (True)
sInput = MSComm1.Input
If (Len(sInput) > 0) Then
MSComm2.Output = sInput
End If

By Mariano Biltes on 24 October, 2005 - 11:02 pm

Is very easy to use this control. I uploaded a ie for u is in my site.

at end there is a link VBCOMM, click it and enjoy!!!!


I am using Atmel 8051 in our project. Please give me information regarding how to download visual basic hex file into the 8051 memory. Give the information regarding suitable cross compiler with respect to this requirement.

Thanks and regards,


I am working on a project which inputs 3 different measurements to a PC using RS232. I am new to VB 6. A PIC18F microcontroller is sending these 3 values to the PC, the VB program is supposed to display them on a simple stand alone program. I dont know much about programming in VB. I did research online but was unable to find a sample code meeting my design specifications. Are there any resources, sample code or suggestions for attacking this problem.
Thank you.

have a look at


i also need your help. right now i developing a payment terminal program and the the terminal can send data via modem and another modem at the server receive the data... how i capture the data from the teminal and the modem at the server is using serial port communication...

pls. i need u guys help.

By Brian E Boothe on 2 July, 2006 - 8:14 pm

why is it that alot of these industrial control guys have no clue what a search engine is,, geesh

These productive microcontroller tools were developed by Hanover Software

BXC-51 BASIC 8051 Cross-Compiler <bxc51.html> - the BASIC-52
Compiler of choice

BEC-51 BASIC 8051 Cross-Compiler <bec51.html> - the Blue Earth
BASIC Compiler of choice

BXC-51 Library Toolkit <bxc51lt.html> - the BASIC/Assembly
programmers toolkit

BXC-51 IDE <bxc51ide.html> - the BXC-51 programmer's integrated
development environment (IDE)

BXC-51 Simulator <bxcsim.html> - the BXC-51 programmer's
simulation tool

QComm <qcomm.html> - the communications scripting tool

Infinitor <inf.html> - the programmer's editor

SXA-51 8051 Cross-Assembler <sxa51.html> - 8051 Cross-Assembler

BXA-51 8051 Cross-Assembler <bxa51.html> - 8051 Cross-Assembler

By Rachna Nambiar on 12 May, 2006 - 12:56 am


Even I have the same problem. Completely new to Visual Basic. I have to get data form the serial port, and display it along with the time at which it was received. Can anyone send me a code how to do this. the data will be 2 Ascii characters at a time.

I would be very grateful if i could get this code.. its very very urgent.

Email address is


I have an idea, but dont know whether it will workout or not. just try to send vb codes as strings in C code then generate hex code.. try out if it works pls let me also know...

By batu_industry on 2 February, 2007 - 12:43 am


If you have problem with Atmel 8051, I'll help you
make some program or use Visual Basic.

Send your question to: batu_industry @ yahoo. com

Hello manjula,

I was also in search of that, here's what I can suggest.

One method is to use get a ready made program burner from the market. Second is to construct a programmer of your own. You will get nice, simple circuits at the following link:


this code does not work even after the MSComm settings are done

> The easiest way to access COM ports in Visual Basic 6 is by placing the
> Microsoft Comm control on a form, and writing code to read and write each serial port.
---- snip ----

> Example of an infinite loop that takes data from one port and echos it onto another -

> Dim sInput as String
> While (True)
> DoEvents
> sInput = MSComm1.Input
> If (Len(sInput) > 0) Then
> MSComm2.Output = sInput
> End If
> Wend


look you have to use mscomm control in visual basic, the mscomm control is a control that is include into visual basic its icon is like a phone.

into of its properties there are de comm 1 o comm 2 setting, speed, parity etc...

the instruction to read de port is input and the instruction to write is output is very easy to use.

By Anonymous on 1 March, 2005 - 10:33 pm


we want to develope one project on communication between mobile and computer. i use serial port and data cable, i want to transfer my message from my pc to mobile but i don't know how to develop this project in vb6. so, please help me as soon as possible.

By Krishnakant on 7 October, 2004 - 12:40 am

Even I am doing the same project i.e. sending & reciving messages using USB thru GSM modem.

If you got the code please send me at the email address below.

I would like a copy of the code too.

i hope that u send the code to my e-mail too.

me also, thanks

Can somebody send me a sample code of how to interface the serial port with VB? basically i just want to read in 8 bits from and A/D converter.

If you got the code please send it to me at the email address below.

Can somebody send me the sample code of how to interface the serial port with VB6 please?
can you send it to

thanks for your help.

By Engr. Shahid bilal on 5 January, 2005 - 8:36 pm

1- go to "project" menu<br>
2- select "components"<br>
3- on control tab click the check box of "Microsoft Comm control 6.0"<br>
4- u will see a sign of telephone on General where u can find out text box, label, etc.<br>
5- select that MSCOMM control object and drag and drop on your Form1.<br>
6-double click on form1.<br>
7-copy & paste the following code:<br>

Private Sub Form_Load()

com1.CommPort = 2 ' comm port no.
com1.Settings = "1200,e,7,2"
com1.RThreshold = 24 'no. of chr to recive
com1.InputLen = 0 ' no. of chr on which oncomm event fires

com1.PortOpen = True 'open comm port

End Sub

Public Sub Com1_OnComm()
Dim txtBuf
Dim i As Integer
Dim c As Integer
Dim buffer
Dim stable
Dim EVMsg$
Dim ERMsg$
buffer = ""
txtweight.Text = ""
With com1

Select Case .CommEvent
Case comEvReceive
buffer = .Input
For i = 1 To Len(txtBuf)
c = Asc(Mid$(txtBuf, i, 1))
If (c < 32 Or c > 126) Then
txtweight = txtweight & "" & Hex(c) & ""
txtweight = txtweight & Chr(c)
End If

Next i

' Error messages.
Case comBreak
ERMsg$ = "Break Received"

Case comFrame
ERMsg$ = "Framing Error"
Case comOverrun
ERMsg$ = "Overrun Error"
Case comRxOver
ERMsg$ = "Receive Buffer Overflow"
Case comRxParity
ERMsg$ = "Parity Error"

Case Else
ERMsg$ = "Unknown error or event"
End Select

End Sub

9- if any problem contact me, tell me how many char u want to tx/rx.


i have seen ur code for serial port communication using VB. it would be extremely useful if u wud tell me whether we need to put an command box. if yes, then what code should be written? ur code doesnt use a command box. then how do we receive our message back?

kindly reply back at this id.

That is ok. But how will i USB port to Send or Receive a Data in Vb6. Because MSCOMM control is not able to access USB port.

Hello there,

you can you a USB to RS232 converter.

Hello there,

Could you please help me by sending VisualBasic code which can be used to send and receive thru a USB to RS232 converter?

Appreciate your help in advance.



i am madhu. i am working as a vb programmer. i am also
having same problem in reading data from pbx and write it as a log file. if u have any code plz tell me.

my mail id

i am waiting for ur reply.

In the code snippet you have written:
for i = 0 to txtbuf
But, nowhere in the program the content of txtbuf
is mentioned. So i couldnt get ur point.

Thanking you

By v.r.t.kumar on 27 January, 2005 - 4:45 pm

Respected Sir,

I am doing a project (weighing bridge software) which takes data from com1 port connected to a device.

The weigh-bridge vendor already given a software written in foxpro. In that software only it takes the data.

Now I am planning the same project write into vb. But in my code the data did not come from the com1 port. no data comes at all.

please give me a solution.

thaking you sir

with regards,

i am also trying for the same problem. If you have got the source code please send the below email id.

thanks & regards

i am geting a 424 error while running something in the line "com1.CommPort = 2 'comm port no." is wrong.

By Payal sheth on 19 March, 2005 - 3:04 pm

Can u please tell me when will the Com1_OnComm event will fire ...

well i m transmitting the data through com1.output but like how will i read the port...
what i should write that the event com1_onComm fires

Hi there!
I did check your code on serial port in VB.
Somehow it isn't working for me.

Could you please resend me the code as i need it for my project.

My email address is :



I am trying to write some data @ com1 and read the same data. Here is my sample code. But I could not send or receive and data.

What ever data I send is in txt_tx box and the receive data should be ib txt_rtx box.

Private Sub cmdexit_Click()
End Sub

Private Sub cmdtrigger_Click()

Dim i, j As Integer

i = MSComm1.OutBufferCount
MsgBox i

j = MSComm1.InBufferCount
MsgBox j

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

MSComm1.SThreshold = 1

MSComm1.Output = KeyAscii
txt_tx.Text = KeyAscii

MSComm1.RThreshold = 1

End Sub

Private Sub Form_Load()

MSComm1.CommPort = 1 'Use com1 port
MSComm1.Settings = "38400,N,8,1" 'Port Settings

MSComm1.InputLen = 0 'Read entire Rx Buffer
MSComm1.PortOpen = True 'open port

End Sub

Private Sub MSComm1_OnComm()

If MSComm1.CommEvent = comEvReceive Then
txt_rx.Text = MSComm1.Input
MsgBox "Sorry No Data In Rx Buffer"

End If

End Sub

By Malik Saqib on 12 July, 2007 - 11:59 pm

Instead of this:

> i = MSComm1.OutBufferCount
> MsgBox i
> j = MSComm1.InBufferCount
> MsgBox j

Write this:

> i=mscomm1.output
> msgbox i

> mscomm1.input=j

By Anonymous on 1 April, 2005 - 9:42 pm

i want a code to send and receive sms from pc.


i would like to know how to/what is the code in VB6, i want to create the interface that able to read and write the sms via serial port (between pc & mobile phone) using PDU format and ATcommands some sort like that....

Thank You.

Hi, i am currently working on a project dealing with the eyes of robot. I am currently struggling to use VB6 to enable the camera through the serial port to communicate with my robot.

could you kindly please help me over here? thks!


By Anonymous on 2 June, 2005 - 11:37 pm


i'm working on a project that transfer a text data between two computer and use the following code:

Private Sub cmdExit_Click()
End Sub

Private Sub cmdReceive_Click()
If (Len(txtReceive) > 0) Then
txtReceive = vbNullString
txtReceive.Text = MSComm1.Input
End Sub

Private Sub cmdSend_Click()
If (Len(txtSend) > 0) Then ' make sure that there is text to send
If (MSComm1.PortOpen = True) Then ' make sure the serial port was initialized
' send the text as well as a carriage return and line feed appended to the end
MSComm1.Output = txtSend & vbCr & vbLf
MsgBox "ERROR: serial port not initialized"
End If
MsgBox "ERROR: there is no text to send"
End If
' after sending clear the text out of the input box
txtSend = vbNullString
End Sub

Private Sub cmdStart_Click()

MSComm1.CommPort = 1
' 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
' generate an event on every character received
MSComm1.RThreshold = 1
' Open the port.
MSComm1.PortOpen = True
' Note: we should set the multiline property to True here in code but it is a read-only property
' do not allow the user to change the received text
txtReceive.Locked = True
' clear the intial text boxes
txtReceive.Text = vbNullString
' Send the attention command to the modem.
InputData = ""
End Sub

Private Sub MSComm1_OnComm()
Dim InputData As String

Select Case MSComm1.CommEvent

' Errors
Case comEventBreak ' A Break was received.
MsgBox "Break received"
Case comEventFrame ' Framing Error
MsgBox "Framing error"
Case comEventOverrun ' Data Lost.
MsgBox "Overrun error"
Case comEventRxOver ' Receive buffer overflow.
MsgBox "Receive Buffer overflow"
Case comEventRxParity ' Parity Error.
MsgBox "Parity Error"
Case comEventTxFull ' Transmit buffer full.
MsgBox "Transmit Buffer full"
Case comEventDCB ' Unexpected error retrieving DCB
MsgBox "DCB error"

' Events
Case comEvCD ' Change in the CD line.
MsgBox "Carrier Detect changed state"

Case comEvDSR ' Change in the DSR line.
MsgBox "Data Set Ready (DSR) changed state"
Case comEvRing ' Change in the Ring Indicator.
MsgBox "Ring Indicator (RI) changed state"
Case comEvReceive ' Received RThreshold # of characters
' MsgBox Str$(MSComm1.RThreshold) & " Characters received"
' While (MSComm1.InBufferCount > 0)
' txtReceive = txtReceive & MSComm1.Input
' only keep the last 5,000 characters -- throw away any characters older than that
' txtReceive = Right$(txtReceive, 5000)
' Wend

InputData = InputData + MSComm1.Input
Case comEvCTS ' Change in the CTS line.
MsgBox "Clear To Send (CTS) changed state"
ReceivedDataTextBox.Text = InputData
InputData = ""

Case comEvSend ' There are SThreshold number of characters in the transmit buffer
MsgBox Str$(MSComm1.SThreshold) & " Characters remaining in transmit buffer"
Case comEvEOF ' An EOF charater was found in the input stream
MsgBox "EOF received"
End Select
End Sub

but i couldn't recieve any character.
Can any one help me in correcting this code.
if there is any contact me with the ff address.<br>

thank you!

By engr Shahid bilal on 7 May, 2006 - 2:26 pm

I used your code for getting 10 characters from an 8051 microcontroller thru the rs-232 serial interface with the com 1 port. so i modified threshold value as 10, and the com1.Settings = "9600,N,8,1". But it still isnt working..we tested our microcontroller code with the hyperterminal so there is no problem there.

plz do help us out, this is a part of our project. Thanks.


me too working on a similar project. it would be of great help if u could send me the code to transfer data serially using Vb 2 serial port...


Not sure if i'm doing this right. Its my first time in a long time. I'm trying to build a CNC work station at home in my shop. I have read your com port program and it seam's strait forward enough. I'm trying to talk to a Stamp mother board Via (USB/com port) on the mother board i have wired a Hataci accallarator chip. Its Not meant for my application but it does read X Y Z axes AND Gforce.

This is the program that is loaded on the Stamp CPU eeprom and the Values it returns to the stamp program but i want to read the com port my self and using Stand alone VB program. The com. program u posted will probably work fine. The last time i programed anything was 17 years ago so im mostly trial and error right now.

'{$STAMP BS2pe}
'{$PBASIC 2.5}
' ==========
' ===============================================================
' File....... H48C_3-Axis.BS2
' Purpose.... Hitachi H48C 3-Axis Accelerometer Demonstration
' Author..... Copyright (c) 2005-2006 Parallax, Inc.
' E-mail.....
' Started....
' Updated.... 02 FEB 2006
' =========================================================================

' -----[ Program Description ]---------------------------------------------
' Test program for the H48C 3-Axis Accelerometer module.
' Connections:
' +------------+
' | * |
' CLK | o o | Vdd (+5v)
' | +--+ |
' DIO [ o | | o | CS\
' | +--+ |
' Vss | o o | 0G (free-fall indication)
' | |
' +------------+
' How it Works:
' An onboard MCP3204 12-bit ADC is used to read the VRef, X-, Y-, and
' Z-axis outputs from the Hitachi H48C accelerometer. The reference
' voltage output from H48C is 1.65 volts (3.3 / 2).
' After reading the reference voltage and an output channel the g-force
' for the channel is calculated with this formula:
' axis - vref 3.3
' G = ----------- x ------
' 4095 0.3663
' For use in the program the forumla can be simplified to:
' G = (axis - vref) x 0.0022
' To allow the display of fractional g-force in the integer system of the
' BASIC Stamp we multiply 0.0022 by 100 -- this will allow us to display
' g-force in 0.01g units.

' -----[ Revision History ]------------------------------------------------

' -----[ I/O Definitions ]-------------------------------------------------

Dio PIN 02 ' data to/from module
Clk PIN 08 ' clock output
CS PIN 03 ' active-low chip select

' -----[ Constants ]-------------------------------------------------------

XAxis CON 0 ' adc channels
YAxis CON 1
ZAxis CON 2
VRef CON 3

Cnt2Mv CON $CE4C ' counts to millivolts
' 0.80586 with **
GfCnv CON $3852 ' g-force conversion
' 0.22 with **

' -----[ Variables ]-------------------------------------------------------

axis VAR Nib ' axis selection
rvCount VAR Word ' ref voltage adc counts
axCount VAR Word ' axis voltage adc counts
mVolts VAR Word ' millivolts
gForce VAR Word ' axis g-force

dValue VAR Word ' display value
dPad VAR Nib ' display pad

' -----[ EEPROM Data ]-----------------------------------------------------

' -----[ Initialization ]--------------------------------------------------

HIGH CS ' deselect module
DEBUG CLS, ' paint display
"=========================", CR,
"H48C 3-Axis Accelerometer", CR,
"=========================", CR,
" Count Volts G ", CR,
" ----- ----- -----", CR,
"VRef ", CR,
" X ", CR,
" Y ", CR,
" Z "

' -----[ Program Code ]----------------------------------------------------

FOR axis = XAxis TO ZAxis ' loop through each axis
GOSUB Get_H48C ' read vRef & axis counts

dValue = rvCount ' display vRef count

dValue = axCount ' display axis count
DEBUG CRSRXY, 6, (7 + axis)

mVolts = rvCount ** Cnt2Mv ' convert vref to mv
DEBUG CRSRXY, 13, 6, ' display
DEC (mVolts / 1000), ".",
DEC3 mVolts

mVolts = axCount ** Cnt2Mv ' convert axis to mv
DEBUG CRSRXY, 13, (7 + axis),
DEC (mVolts / 1000), ".",
DEC3 mVolts

' calculate g-force
' -- "gForce" is signed word

IF (axCount >= rvCount) THEN
gForce = (axCount - rvCount) ** GfCnv ' positive g-force
gForce = -((rvCount - axCount) ** GfCnv) ' negative g-force
DEBUG CRSRXY, 20, (7 + axis), ' display g-force
" " + (gForce.BIT15 * 13),
DEC1 (ABS(gForce) / 100), ".",
DEC2 ABS(gForce)

' -----[ Subroutines ]-----------------------------------------------------

' Reads VRef and selected H48C axis through an MCP3204 ADC
' -- pass axis (0 - 2) in "axis"
' -- returns reference voltage counts in "rvCount"
' -- returns axis voltage counts in "axCounts"

SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [rvCount\13] ' read ref voltage counts
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, axis\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [axCount\13] ' read axis voltage counts

' -------------------------------------------------------------------------

' Right-justify value in 5-digit field
' -- move cursor first, then call with value in "dValue"

LOOKDOWN dValue, >=[10000, 1000, 100, 10, 0], dPad
DEBUG REP " "\dPad, DEC dValue

Any help would be gratefully appreciated .Please forgive me my spelling and grammer. Robbie64


i'm having the same problem as yours. I try a lot of alternatives but still fail to do it. So, i hope that you can send me the vb code. Thanks... Your help will be appreciated.

Jumping on the bandwagon... i have a similar issue where I want to input data that is coming into the serial port, look at the last line of data, and then if that number in the last line is bigger than another number i want to create a pop-up window that says a message on it. Is this difficult to do? and if not, can someone send me the code on how you would do it? Thanks for your help.

By Neil Kingston on 5 December, 2004 - 11:20 pm

I would not recommend using infinite loops, instead use the MSComm event.

Private Sub MSComm1_OnComm()

Dim strInput As String
Dim intInput As Integer
Const intMax As Integer = 150

strInput = MSComm1.Input
' Locate the value you are interested in within the input string
' in this example it is the last three characters, which we convert to an integer
intInput = CInt(Right(strInput, 3))
If intInput > intMax Then
MsgBox strInput & " is too large, please make it smaller!"
End If

End Sub

Neil Kingston<br>
Data Layers

Connecting processes with IT<br>

Is it possible to send the text from visual basic thru serial com? Instead of using keyboard i will use pc to send input. (it works as keyboard.)

need help im novice in this language!!! Pls. send me a copy of your code. Thanks...

email add:

Place a Microsoft Comm control on the form and send the data to its output property. For example if the data comes from txtAge the code would be

MSComm1.output = txtAge.text

Where MSComm1 is the Microsoft Comm control

By Anonymous on 2 March, 2005 - 3:14 pm


i want to pass a particular word on my form to be display as a label i have this code is there any way i can tell if the word is right, and been received by displaying the word. i can see the word lama. but no labe display on form

Option Explicit

Private Sub Form_Load()

Dim Buffer As String
' 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 = "lama " & vbCr ' Ensure that
' the modem responds with "OK".
' Wait for data to come back to the serial port.

Buffer$ = Buffer$ & MSComm1.Input
If InStr(Buffer$, "Test") Then

Label1.Caption = "OEM4 Detected"

End If

End Sub

By Thomas L. Burgin on 30 March, 2005 - 10:10 pm

I have not been able to get the MScomm1 statement to work with VB .net

What must be done to get it to work?

Or better yet does someone have a solution to read text from a serial port using visual basic .net?


By Anonymous on 1 April, 2005 - 8:46 pm


The serial port takes in a binary number i.e 1010, I want VB to take the binary word and based on the number received, it will display an alert in a msgbox or a label. Could some help me with the code that lets the serial port input this data to VB and store it in some sort of variable. This is the code I have, and i am not sure if it is right.

Private Sub Form_Load()

frmVSS.Top = (Screen.Height - frmVSS.Height) / 2
frmVSS.Left = (Screen.Width - frmVSS.Width) / 2
com1.CommPort = 1 'comm port no.
com1.Settings = "4800,N,8,1" 'Port Settings
com1.RThreshold = 4 'no. of characters to receive
com1.InputLen = 4 'no. of binary characters on which oncomm event fires
com1.PortOpen = True 'open comm port

End Sub

Any help is greatly appreciated.


i wanna design a program that read data from serial port
i create an infra-red circuit which can accept signal from any remote control and i tested it with downloaded programs and it works.

so can anyone help me for design that program?


I m having the same problem with u. At first i wrote my code in VB6, then I tried to convert it to (by using a new pc with only installed) but failed.

Any solution?

hi scorpioboy!

products -
active experts sms messaging server.
activeexperts sms pager and toolkit.
should be interesting.

hope it works out.

By vijay sohra on 8 January, 2006 - 12:03 pm

why dont u use mscomm control. it has properties to do that. its a control with telephone pic on it
its available with all vb enterprise edition

If you are using VB .NET there is a free component you can use to send and receive SMS using a PC connected mobile phone. Follow the following link

I am trying to use two serial ports (and perhaps more) on the same form with VB6, I have no problems getting one MSComm event defined and working but when I try to add the second I get a "duplicate Definition" error. Any ideas as to why this wont work for me?

This code works great:

Dim WithEvents MSCommRatio1 As MSCommLib.MSComm

Private Sub Form_Open(Cancel As Integer)
'code to load the form and
'set up the comm
End Sub

Private Sub MSCommRatio1_OnComm()
'code to read the port at the correct time.
'and put the data were I want it
End Sub

This code gives the error:

Dim WithEvents MSCommRatio1 As MSCommLib.MSComm
Dim WithEvents MSCommRatio2 As MSCommLib.MSComm

Private Sub Form_Open(Cancel As Integer)
'code to load the form and set up
'the comm objects on two different ports
End Sub

Private Sub MSCommRatio1_OnComm()
'code to read the port at the correct time.
'and put the data were I want it
End Sub

Private Sub MSCommRatio2_OnComm()
'code to read the port at the correct time.
'and put the data were I want it
End Sub

you can perform one step at once and obtein good results too.
just to say that its possible using the same port.

think a litle more... after that a show you how.


By Anonymous on 2 April, 2007 - 11:24 pm

One more question... how to generate the list of com ports available in the system in vb?

By donato aldea on 3 October, 2008 - 9:31 pm

Try this site.

Can somebody send me a sample code of how to interface the serial port with VB? basically i just want to read in 16 bits from and A/D converter.

If you got the code please send it to me at the email address below.

hareensunny [at]

That is reading binary data bytes. We switched to SuperCom ActiveX for that. Replaced MSComm in no time (same functions) and got our binary data bytes. Look for a DEMO at