Sign in to follow this  
Followers 0
korted123

VBA control of serial port

11 posts in this topic

Hello, I am trying to send/receive information via my serial port, and am having a strrange problem: I can read and write successfully via VBA only after establishing a connection with hyperterminal and then closing hyperterminal. I am using simple commands like: Open "COM1" For Output As #1 Print #1, "Text" Close #1 The VBA itself will not establish the serial connection, but works fine after initialization by hypertermial. Any ideas??

Share this post


Link to post
Share on other sites
You might have to use the MScomm module: Private Sub Form_Load() Dim str As String MSComm1.CommPort = 1 MSComm1.Settings = "9600,n,8,1" MSComm1.InputLen = 0 MSComm1.PortOpen = True MSComm1.Output = "hello" MSComm1.PortOpen = False End Sub This is off the top of my head....but see if it works.

Share this post


Link to post
Share on other sites
This is the syntax for QBASIC or GWBASIC. Chakorules is correct when using Visual Basic for Applications

Share this post


Link to post
Share on other sites
It's under Additional Controls

Share this post


Link to post
Share on other sites
I ran the following: Private Sub Form_Load() Dim mscomm1 As Mscomm Dim str As String mscomm1.CommPort = 1 mscomm1.Settings = "9600,n,8,1" mscomm1.InputLen = 0 mscomm1.PortOpen = True mscomm1.Output = "hello" mscomm1.PortOpen = False End Sub ...and received the following error: "Object variable or With block variable not set (Error 91)" I can delete the mscomm1 declaration, but only get a different error. What am I missing?

Share this post


Link to post
Share on other sites
...and I have the reference "MS COMM Control 6.0" added...

Share this post


Link to post
Share on other sites
I believe you can remove the following line since it is already refrenced as a control. Then what error do you recieve?? Dim mscomm1 As Mscomm If you recieve "Object Required" you need to add the module onto the form. JJ Edited by TechJunki

Share this post


Link to post
Share on other sites
We're getting closer...when I try to add MSCOMM to the form, I get: "The control could not be created because it is not properly licensed" The help for this item does not exist. How do I "properly license" this? I have tried both references and additional controls, where MSCOMM is selected, but the error remains. I keep looking within VBA, but see no other means of installing or registering this.

Share this post


Link to post
Share on other sites
There are a couple of versions of the VB6 development package. The Professional Edition includes the MSCOMM object. The Student Edition does not. If you try to add the MSCOMM object to a form under the Student Edition, you get that message about licensing. The VBA included with Excel (or whatever VBA you're trying to use) may not let you design around MSCOMM objects. It may only let you use then at runtime. One other possibility to check is to look for a file called 'MSComm32.ocx' on your computer. It's normally found in the Windows\System32 directory.

Share this post


Link to post
Share on other sites
You should be able to edit an excel file with the MSComm object already embedded. Try this, let us know if it works. JJ MSComm.zip

Share this post


Link to post
Share on other sites
That works great! I can edit to my hearts content, too. Now all I need to do is get this to run as well in RSView32 as it does in Excel... Thanks Guys!!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0