Hello there,

I am making a form application with a serial interface. I am getting the "Error C2065: '_serialPort' : undeclared identifier on line of decleration of _serialPort.

How can the software complain that the identifier is not declared on the line where it is declared?

I tried to google the thing, but couldn't get a clear answer.

What is going on?

	private: String^ sendData(String^ data) {
		try {
			String^ message;

			// Create a new SerialPort object with default settings.
			_serialPort = gcnew SerialPort();

			// Allow the user to set the appropriate properties.
			_serialPort->PortName = comboBox1->Text;
			_serialPort->BaudRate = 9600;
			_serialPort->Parity = Parity::None;
			_serialPort->DataBits = 8;
			_serialPort->StopBits = StopBits::One;
			_serialPort->Handshake = Handshake::None;

			// Set the read/write timeouts
			_serialPort->ReadTimeout = 500;
			_serialPort->WriteTimeout = 500;



			message = _serialPort->ReadLine();
		catch (Win32Exception^ ex) {
		return message;
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::IO::Ports;
#include "stdafx.h"
#include "Form1.h"
#using <System.dll>
#include "stdlib.h"


Kind regards,