I'am a beginner in Visual Basic 6.0. Now I try to write a ActiveX control
that is in charge of communication through COM1. So I decided to adopt
MSComm control.
I draged a button onto the usercontrol.Then I wrote some statements in
its double-click event handler,like this:
Private Sub Command1_Click()
Dim MyComm As MSComm
MyComm.CommPort = 1
MyComm.Settings = "9600,N,8,1"
MyComm.PortOpen = True
End Sub
Then I started to run it in a web page by printing F5. When I double-clicked
the button, a message box jumped out on which it says as following:
Run-time error '91':
Object variable or With block variable not set
Please tell me why this happened? Where did I wrote incorrectly? Thank all
of you!
Adrian
Chen
Nico Notter - 09 Aug 2008 16:22 GMT
Maybe like this?
> Private Sub Command1_Click()
> Dim MyComm As MSComm
Set MyComm as New MSCom
> MyComm.CommPort = 1
> MyComm.Settings = "9600,N,8,1"
> MyComm.PortOpen = True
::::::::
Set MyComm=Nothing
> End Sub
KenHalter - 11 Aug 2008 21:48 GMT
>I'am a beginner in Visual Basic 6.0. Now I try to write a ActiveX control
>that is in charge of communication through COM1. So I decided to adopt
[quoted text clipped - 4 lines]
> Private Sub Command1_Click()
> Dim MyComm As MSComm
MSComm is a control and it needs a form. You can't create instances of it for
use "out of thin air", so you'll need to either add a form to the project and
drop the control there, or attempt to create one at runtime and force it to
"live" on an existing form.
Here's a class that wraps the Win32 APIs that deal with serial communications
that you can try, but if you want to stick with the control, you'll need a
form.
mComm Class Module
http://home.comcast.net/~hardandsoftware/CRC32.htm