Public Function Port Test

K

ksjent

Hi everybody!

I'm new here and I desperatly need help. With the following function I
try to see a a device:

Public Function PortTest(COMPortNummer As Integer) As Boolean
MSComm1.CommPort = COMPortNummer
On Error Resume Next
MSComm1.PortOpen = True

If Err = 0 Then
PortTest = True
MSComm1.PortOpen = False
Else
PortTest = False
MSComm1.PortOpen = False
End If
End Function

For Portzaehler = 1 To 16
If PortTest(Portzaehler) Then
MsgBox "COM" + Str(Portzaehler) + " verfügbar"
End If
Next

The problem is that the compiler says to me that the command
"MSComm1." is error. It seems that I have to put a definition, and I
have no clue how to do it. I'm not a programmer, but I urgently need a
solution. Might it be that I have to add a line like "MSComm1.CommPort
= 1", and if yes, where to put it? Thank you for any kind of help!

Best wishes, Gremlin
 
K

ksjent

Hi everybody!

I'm new here and I desperatly need help. With the following function I
try to see a a device:

Public Function PortTest(COMPortNummer As Integer) As Boolean
MSComm1.CommPort = COMPortNummer
On Error Resume Next
MSComm1.PortOpen = True

If Err = 0 Then
PortTest = True
MSComm1.PortOpen = False
Else
PortTest = False
MSComm1.PortOpen = False
End If
End Function

For Portzaehler = 1 To 16
If PortTest(Portzaehler) Then
MsgBox "COM" + Str(Portzaehler) + " verfügbar"
End If
Next

The problem is that the compiler says to me that the command
"MSComm1." is error. It seems that I have to put a definition, and I
have no clue how to do it. I'm not a programmer, but I urgently need a
solution. Might it be that I have to add a line like "MSComm1.CommPort
= 1", and if yes, where to put it? Thank you for any kind of help!

Best wishes, Gremlin

If someone could send me the example code in english (mine is german
version) would be even better!
 
T

Tony Strazzeri

I think you don't have any resource that communicates with the comm
port. VBA certainly doesn't have this. I think this may be available
in the "MSComm32.ocx" Activex control. If you have it installed you
can add a reference to it from your VBA IDE under References.

I think it odd that you are posting the query to an MS Word group.

Anyway a quick search using "how to open CommPort vba" came up with a
couple of worthwhile directions including the above control.

Have a look at these;

http://www.tech-archive.net/Archive/Excel/microsoft.public.excel.programming/2004-05/7068.html
http://mc-computing.com/languages/SerialIO.htm
http://www.activexperts.com/activcomport/howto/vba/

I can't vouch for any of these but they seemed worth a look.

Good Luck
Cheers
TonyS.
 
K

ksjent

I think you don't have any resource that communicates with the comm
port. VBA certainly doesn't have this. I think this may be available
in the "MSComm32.ocx" Activex control. If you have it installed you
can add a reference to it from your VBA IDE under References.

I think it odd that you are posting the query to an MS Word group.

Anyway a quick search using "how to open CommPort vba" came up with a
couple of worthwhile directions including the above control.

Have a look at these;

http://www.tech-archive.net/Archive.../www.activexperts.com/activcomport/howto/vba/

I can't vouch for any of these but they seemed worth a look.

Good Luck
Cheers
TonyS.

Thank you very much Tony!
I'm sorry about posting the message to a word group.
I realized afterwards that this is not a general vba discussion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top