Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type 'MSComm' is not defined -- error

Status
Not open for further replies.

FoxEgg

Programmer
Mar 24, 2002
749
AU
Error problem ....Type 'MSComm' is not defined

Background

I am using VB.net (express edition)

I have the following code copied from the Microsoft Web Page

How to access serial ports by using VB.Net


Code:
Module Module1

    Sub Main()
        'New a MSComm control
        Dim MSComm1 As MSComm
        MSComm1 = New MSComm
        ' Buffer to hold input string.
        Dim Buffer As String
        ' Use the COM1 serial port.
        MSComm1.CommPort = 1
        ' 9600 baud, no parity, 8 data, and 1 stop bit.
        MSComm1.Settings = "9600,N,8,1"
        ' Tell the control to read the whole buffer when Input is used.
        MSComm1.InputLen = 0
        ' Open the serial port.
        MSComm1.PortOpen = True
        Console.WriteLine("Open the serial port.")
        ' Tell the control to make the Input property return text data.
        MSComm1.InputMode() = InputModeConstants.comInputModeText
        'Clear the receive buffer.
        MSComm1.InBufferCount() = 0
        ' Send the attention command to the modem.
        MSComm1.Output = "ATV1Q0" & Chr(13)
        Console.WriteLine("Send the attention command to the modem.")
        Console.WriteLine("Wait for the data to come back to the serial port...")
        ' Make sure that the modem responds with "OK".
        ' Wait for the data to come back to the serial port.
        Do
            Buffer = Buffer & MSComm1.Input
        Loop Until InStr(Buffer, "OK" & vbCrLf)
        ' Read the "OK" response data in the serial port.
        ' Close the serial port.
        Console.WriteLine("Read the OK response data in the serial port.")
        MSComm1.PortOpen = False
        Console.WriteLine("Close the serial port.")
    End Sub

End Module

I have registrered the MSComm32.ocx
I have added MS Comm Control

I get the persistent error

Type 'MSComm' is not defined (line 9)
Type 'MSComm' is not defined (line 10)
'Input ModeConstants' is not declared (line 23)

(These lines might not be exact the same as I have typed above)

Can anyone get me past this ??? Much appreciated

Foxegg
 
Did you include the Imports MSCommLib ?

Also, why not use the .NET control named SerialPort1 ? You will find it in the toolbox under the Components tab.

Hope i helped!
 
What version of the .net framework are you targeting? Under v1.x serial access was via an add-on assembly. Only in v2.0 (the 2005 versions of VB & Visual Studio) did serial access become part of the framework itself.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
"I am using VB.net (express edition)"

... 2005 version - v2.0 framework
 
Thanks all... (Now Sunday morning here in Oz)

OK in reverse order (For Chip and Tip)

From the Help -> About ->

Microsoft Visual Studio 2005
Version 8.0 50727.42
2005 Microsoft

and

MS .NET Framework
Version 2.0 50727
2005 Microsoft


For TipG

Did you include the Imports MSCommLib ?

I followed the Instructions EXACTLY the way as designated in


(the code snippet (shown above enclosed in 'code' section)is a direct lift from that page)
I added the reference, which when I check Projct -> MyConsoleApplication Properties -> shows the Reference to MS Comm Control


TipG you asked

Did you include the Imports MSCommLib ?

I looked around before posting and found one help spot that said

Add the following

Code:
Dim MSComm as Object
MSComm = CreateObject("MSCommlib.MSComm")


Which I did and it gave the same error report !!! That is it did nothing to help.

Is that what you mean by "Did you include the Imports MSCommLib ?"... I would not know how to include it otherwise... (<- I am new to VB.Net)

I found the Toolbox... It says there are no useable controls in this group.

...and the reason why I havent done anything with Serial Port is because I am very unsure of myself in this language and looking to learn from pre-tested coded examples..

Cheers

(BTW I even used regsvr32 MSCOmm32.ocx from the RUN command ... it said it registered OK)

FoxEgg
 
Hi ...

I changed Line 3 and 4 to read

Code:
Dim MSComm1 As MSCommLib.MSComm
MSComm1 = New MSCommLib.MSComm


This removed the two errors labelled "Type 'MSComm' is not defined " But it gave me an error

Name 'InputModeConstants' is not declared.

NOW I ONLY HAVE ONE ERROR....

Then I looked around a bit more and changed

Code:
MSComm1.InputMode() = InputModeConstants.comInputModeText
to

Code:
MSComm1.InputMode() = MSCommLib.InputModeConstants.comInputModeText

Gets rid of the 'not declared error'

I have no idea if I have fixed or what I have fixed...

Any clues.. is that Microsoft help site flawed in its code ?

Fox Egg
 
I found the Toolbox... It says there are no useable controls in this group.

So no sorry....

Fxg
 
I have also installed the express editions and i can find it there. Try the next:

1. Right click anywhere on the toolbox and press 'Reset Toolbox', just in case something went wrong. If it isnt there then...
2. Click on the tab 'All windows forms' and see if it is there. If not then...
3. Right click on the toolbox and press 'Choose Items'. In the '.NET Framework Components' scroll down and check the 'SerialPort'. Its namespace should be 'System.IO.Ports' and the Assembly name 'System (2.0.0.0)'

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top