Hi,

im trying to open com2 . whene i clicked on Button Open_com2 the com 2 must be open but i have some problem like the following
1- Type 'IO.Ports.SerialPort' is not defined.
2-'Ports' is not a member of 'IO'.


Can anyone tell me how can I solve this?
please help me i got headache

this all my code i use Visual Studio 2003

VB Code:
  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.  
  26.     'Required by the Windows Form Designer
  27.     Private components As System.ComponentModel.IContainer
  28.  
  29.     'NOTE: The following procedure is required by the Windows Form Designer
  30.     'It can be modified using the Windows Form Designer.  
  31.     'Do not modify it using the code editor.
  32.     Friend WithEvents open_com2 As System.Windows.Forms.Button
  33.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  34.         Me.open_com2 = New System.Windows.Forms.Button
  35.         Me.SuspendLayout()
  36.         '
  37.         'open_com2
  38.         '
  39.         Me.open_com2.Location = New System.Drawing.Point(56, 88)
  40.         Me.open_com2.Name = "open_com2"
  41.         Me.open_com2.Size = New System.Drawing.Size(184, 64)
  42.         Me.open_com2.TabIndex = 0
  43.         Me.open_com2.Text = "Open Com2"
  44.         '
  45.         'Form1
  46.         '
  47.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  48.         Me.ClientSize = New System.Drawing.Size(292, 266)
  49.         Me.Controls.Add(Me.open_com2)
  50.         Me.Name = "Form1"
  51.         Me.Text = "Form1"
  52.         Me.ResumeLayout(False)
  53.  
  54.     End Sub
  55.  
  56. #End Region
  57.  
  58.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles open_com2.Click
  59.  
  60.  
  61.         'usually, you would declare the serial port at form level and initialize
  62.         'it in the constructor so you can get responses from the port
  63.  
  64.         'declare the serial port and set it for 4800,N,8,1
  65.         Dim serial As New IO.Ports.SerialPort("COM2")
  66.         serial.BaudRate = 4800
  67.         serial.Parity = IO.Ports.Parity.None
  68.         serial.DataBits = 8
  69.         serial.StopBits = IO.Ports.StopBits.One
  70.  
  71.          'make sure the port is open
  72.         Try
  73.             If Not serial.IsOpen Then serial.Open()
  74.         Catch ex As Exception
  75.             'specifically an UnauthorizedAccessException
  76.             'the port is already open somewhere else
  77.             MessageBox.Show("The port is already opened by another process.")
  78.             Exit Sub
  79.         End Try
  80.  
  81.        '
  82.         'uncomment the next line if you do not need to get responses
  83.         'and you are done with the port
  84.         'serial.Close()
  85.  
  86.     End Sub
  87. End Class
  88. '