Hi guys, I'm trying to link a Micro-controller board to my C++ program to control the relays on it. The vendor provided a test software in VB that involved entering the COM port number (4 in my case) and clicking a button to sync up with it, the full software and info on the board is here: [http://www.oceancontrols.com.au/KTA-223.html] under the link 'VB6 test software' link (I've also included .txt attachments of the VB code). I've tried converting the code to C++ along with using namespaces, etc, but I seem to have hit some problems. The code is pretty long so I'll post the relevant things and the errors.

Namespaces being used

using namespace System;
using namespace System::ComponentModel::Container;
using namespace System::ComponentModel;
using namespace System::Windows;
using namespace System::Windows::Forms;

Component Initialisation from VB changed to C++

public ref class zebra : public System::Windows::Forms::Form
	{
	public:
		zebra(void)
		{
			InitializeComponent();
			{
		this->components = gcnew System::ComponentModel::Container();
		System::ComponentModel::ComponentResourceManager ^resources = gcnew System::ComponentModel::ComponentResourceManager(zebra::typeid);
		this->SerialPort1 = gcnew System::IO::Ports::SerialPort(this->components);
			}
		}
}
internal:
array<System::IO::Ports::SerialPort^> ^SerialPort1 = gcnew array<System::IO::Ports::SerialPort^>(this->components + 1);

For the above code, I got the following errors:
error C3083: 'Windows': the symbol to the left of a '::' must be a type
error C3083: 'Forms': the symbol to the left of a '::' must be a type
error C2039: 'Form' : is not a member of 'System'
error C2504: 'Form' : base class undefined
error C2470: 'internal' : looks like a function definition, but there is no parameter list; skipping apparent body
error C3861: 'InitializeComponent': identifier not found
error C2039: 'components' : is not a member of 'zebra'.\zebraDlg.cpp(44) : see declaration of 'zebra'
'ComponentModel': the symbol to the left of a '::' must be a type

and many others. I suspect I may gave failed to include something or that my syntax symbols and function calls are in error.

Lastly, the button that reads the COM port number from a text box to sync with the device (code below).

void CzebraDlg::OnBnClickedButton5()
{
	 try
 {
			if (SerialPort1::IsOpen)
			{
				SerialPort1->Close();
			}
			SerialPort1->PortName = "COM" + IDC_EDIT2->Text;
			SerialPort1->Open();
		}
		catch (Exception ^ex)
		{
			CerrorDlg  cid;  //*** Create an instance of our dialog
			cid.DoModal(); //Display Dialog box
		}
	
}

For the button control, I get errors like
error C2227: left of '->Close' must point to class/struct/union/generic type
error C2227: left of '->PortName' must point to class/struct/union/generic type
and others all dealing with the '->' symbols.

I'm not really sure what the compiler is telling me but I suspect it is just a few lines I may not have. Can anyone help? The VB code I derived it from is from the link above. Thanks a lot in advance!! I'm using MFC to build the GUI.

Edited 6 Years Ago by meepokman: n/a

Attachments
Public Class Form1

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        Try
            If SerialPort1.IsOpen Then
                SerialPort1.Close()
            End If
            SerialPort1.PortName = "COM" & TextBox2.Text
            SerialPort1.Open()
        Catch ex As Exception
            MsgBox("Error Opening " & SerialPort1.PortName)
        End Try
    End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.SerialPort1 = New System.IO.Ports.SerialPort(Me.components)
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.ProgressBar2 = New System.Windows.Forms.ProgressBar
        Me.ProgressBar3 = New System.Windows.Forms.ProgressBar
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.Button10 = New System.Windows.Forms.Button
        Me.Button9 = New System.Windows.Forms.Button
        Me.Button8 = New System.Windows.Forms.Button
        Me.Button7 = New System.Windows.Forms.Button
        Me.Button6 = New System.Windows.Forms.Button
        Me.Button5 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Button4 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.GroupBox3 = New System.Windows.Forms.GroupBox
        Me.Panel4 = New System.Windows.Forms.Panel
        Me.Panel3 = New System.Windows.Forms.Panel
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.Label10 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.Label9 = New System.Windows.Forms.Label
        Me.GroupBox4 = New System.Windows.Forms.GroupBox
        Me.Button11 = New System.Windows.Forms.Button
        Me.txtNewAddr = New System.Windows.Forms.TextBox
        Me.GroupBox5 = New System.Windows.Forms.GroupBox
        Me.Button13 = New System.Windows.Forms.Button
        Me.Button12 = New System.Windows.Forms.Button
        Me.Label14 = New System.Windows.Forms.Label
        Me.Label13 = New System.Windows.Forms.Label
        Me.txtRX = New System.Windows.Forms.TextBox
        Me.txtTX = New System.Windows.Forms.TextBox
        Me.Label12 = New System.Windows.Forms.Label
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Label11 = New System.Windows.Forms.Label
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
        Me.Timer3 = New System.Windows.Forms.Timer(Me.components)
        Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        Me.GroupBox4.SuspendLayout()
        Me.GroupBox5.SuspendLayout()
        Me.SuspendLayout()
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        '
        'ProgressBar1
        '
        Me.ProgressBar1.Location = New System.Drawing.Point(70, 19)
        Me.ProgressBar1.Maximum = 1023
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(178, 13)
        Me.ProgressBar1.Step = 1
        Me.ProgressBar1.Style = System.Windows.Forms.ProgressBarStyle.Continuous
        Me.ProgressBar1.TabIndex = 0
        Me.ProgressBar1.Value = 512
        '
        'ProgressBar2
        '
        Me.ProgressBar2.Location = New System.Drawing.Point(70, 38)
        Me.ProgressBar2.Maximum = 1023
        Me.ProgressBar2.Name = "ProgressBar2"
        Me.ProgressBar2.Size = New System.Drawing.Size(178, 13)
        Me.ProgressBar2.Step = 1
        Me.ProgressBar2.Style = System.Windows.Forms.ProgressBarStyle.Continuous
        Me.ProgressBar2.TabIndex = 1
        Me.ProgressBar2.Value = 512
        '
        'ProgressBar3
        '
        Me.ProgressBar3.Location = New System.Drawing.Point(70, 56)
        Me.ProgressBar3.Maximum = 1023
        Me.ProgressBar3.Name = "ProgressBar3"
        Me.ProgressBar3.Size = New System.Drawing.Size(178, 13)
        Me.ProgressBar3.Step = 1
        Me.ProgressBar3.Style = System.Windows.Forms.ProgressBarStyle.Continuous
        Me.ProgressBar3.TabIndex = 2
        Me.ProgressBar3.Value = 512
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.Label6)
        Me.GroupBox1.Controls.Add(Me.Label5)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.ProgressBar3)
        Me.GroupBox1.Controls.Add(Me.ProgressBar1)
        Me.GroupBox1.Controls.Add(Me.ProgressBar2)
        Me.GroupBox1.Location = New System.Drawing.Point(12, 259)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(254, 78)
        Me.GroupBox1.TabIndex = 3
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Analog Inputs"
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Location = New System.Drawing.Point(28, 56)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(31, 13)
        Me.Label6.TabIndex = 8
        Me.Label6.Text = "1023"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(28, 38)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(31, 13)
        Me.Label5.TabIndex = 7
        Me.Label5.Text = "1023"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(28, 19)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(31, 13)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "1023"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(6, 56)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(16, 13)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "3:"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(6, 38)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(16, 13)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "2:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(6, 19)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(16, 13)
        Me.Label1.TabIndex = 3
        Me.Label1.Text = "1:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.Button10)
        Me.GroupBox2.Controls.Add(Me.Button9)
        Me.GroupBox2.Controls.Add(Me.Button8)
        Me.GroupBox2.Controls.Add(Me.Button7)
        Me.GroupBox2.Controls.Add(Me.Button6)
        Me.GroupBox2.Controls.Add(Me.Button5)
        Me.GroupBox2.Controls.Add(Me.Button3)
        Me.GroupBox2.Controls.Add(Me.Button4)
        Me.GroupBox2.Controls.Add(Me.Button2)
        Me.GroupBox2.Controls.Add(Me.Button1)
        Me.GroupBox2.Location = New System.Drawing.Point(122, 90)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(144, 163)
        Me.GroupBox2.TabIndex = 5
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Relays"
        '
        'Button10
        '
        Me.Button10.BackColor = System.Drawing.SystemColors.Control
        Me.Button10.Location = New System.Drawing.Point(74, 131)
        Me.Button10.Name = "Button10"
        Me.Button10.Size = New System.Drawing.Size(62, 22)
        Me.Button10.TabIndex = 1
        Me.Button10.Text = "ALL OFF"
        Me.Button10.UseVisualStyleBackColor = False
        '
        'Button9
        '
        Me.Button9.BackColor = System.Drawing.SystemColors.Control
        Me.Button9.Location = New System.Drawing.Point(6, 131)
        Me.Button9.Name = "Button9"
        Me.Button9.Size = New System.Drawing.Size(62, 22)
        Me.Button9.TabIndex = 1
        Me.Button9.Text = "ALL ON"
        Me.Button9.UseVisualStyleBackColor = False
        '
        'Button8
        '
        Me.Button8.BackColor = System.Drawing.Color.Red
        Me.Button8.ForeColor = System.Drawing.Color.White
        Me

Hi
Since moving from VB6 to C++ .Net I've ported a few of my VB apps to C++ .Net.
The approach I usually take is to start from scatch!
In your case if you haven't done so already is to download the VB.Net version from the site you linked and use that as a base to work from. You'll find this a bit easier to work with.
Create a new Windows Forms Application in C++ and duplicate all the controls on the VB.Net form onto your C++.net form. Setting all the control properties as you go.
Tip: use meaningful name for the controls (not textBox6, button13) it will make the code more readable and easier to follow especially if you have to start tracking errors.
Once you have added all the controls and before you add ANY code build it and run it. If all is well you will end up with an application with a form identical to the VB version. But of course will do abosultely nothing!
Now the hard bit!
Create the necessary events for the controls as per the VB.Net version and hand code the conversion into C++ syntax. VB.Net and C++ have little in common other than the .Net Framework so you might have the odd work-around to get things to work as they should.
This should get you started.
If you need any help let me know and I will help where I can.

Cheers
Milton

Hello Milton thanks so much for the reply, my VB is actually extremely limited, but I've done what I could above, as well as using converters for some lines I could not really figure out. I also noticed, that VB does not require me to "include" or "use namespace"s as C++ does. I think I might just have missed including something or the syntax of the pointers and symbols I used. Can you see any errors at first glance? Thanks!!

Hi
Yes quite a bit is wrong.
That's why I suggest that you create a new project from scratch. Add the controls you need and let the designer generate the code for you.
See attached Form1.h file.
Maybe this will help you more.

Attachments
#pragma once


namespace Tester {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::GroupBox^  groupBox2;
	private: System::Windows::Forms::GroupBox^  groupBox3;
	private: System::Windows::Forms::GroupBox^  groupBox4;
	private: System::Windows::Forms::Button^  baudButton;
	private: System::Windows::Forms::Button^  openButton;
	private: System::Windows::Forms::TextBox^  portTextBox;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::GroupBox^  groupBox5;
	private: System::Windows::Forms::TextBox^  addressTextBox;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::TextBox^  rxTextBox;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::TextBox^  txTextBox;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Button^  changeButton;
	private: System::Windows::Forms::TextBox^  newaddressTextBox;
	private: System::Windows::Forms::Button^  relay1Button;
	private: System::Windows::Forms::Button^  relay5Button;
	private: System::Windows::Forms::Button^  relay4Button;
	private: System::Windows::Forms::Button^  relay3Button;
	private: System::Windows::Forms::Button^  relay2Button;
	private: System::Windows::Forms::Button^  alloffButton;
	private: System::Windows::Forms::Button^  allonButton;
	private: System::Windows::Forms::Button^  relay8Button;
	private: System::Windows::Forms::Button^  relay7Button;
	private: System::Windows::Forms::Button^  relay6Button;
	private: System::Windows::Forms::Panel^  panel4;
	private: System::Windows::Forms::Panel^  panel3;
	private: System::Windows::Forms::Panel^  panel2;
	private: System::Windows::Forms::Panel^  panel1;
	private: System::Windows::Forms::Label^  label8;
	private: System::Windows::Forms::Label^  label7;
	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::ProgressBar^  progressBar1;
	private: System::Windows::Forms::ProgressBar^  progressBar3;
	private: System::Windows::Forms::ProgressBar^  progressBar2;
	private: System::Windows::Forms::Label^  label14;
	private: System::Windows::Forms::Label^  label13;
	private: System::Windows::Forms::Label^  label12;
	private: System::Windows::Forms::Label^  label11;
	private: System::Windows::Forms::Label^  label10;
	private: System::Windows::Forms::Label^  label9;
	private: System::IO::Ports::SerialPort^  serialPort1;
	private: System::Windows::Forms::Timer^  timer1;
	private: System::Windows::Forms::Timer^  timer2;
	private: System::Windows::Forms::Timer^  timer3;
	private: System::ComponentModel::IContainer^  components;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->rxTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->txTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->addressTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->baudButton = (gcnew System::Windows::Forms::Button());
			this->openButton = (gcnew System::Windows::Forms::Button());
			this->portTextBox = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
			this->changeButton = (gcnew System::Windows::Forms::Button());
			this->newaddressTextBox = (gcnew System::Windows::Forms::TextBox());
			this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
			this->alloffButton = (gcnew System::Windows::Forms::Button());
			this->allonButton = (gcnew System::Windows::Forms::Button());
			this->relay8Button = (gcnew System::Windows::Forms::Button());
			this->relay7Button = (gcnew System::Windows::Forms::Button());
			this->relay6Button = (gcnew System::Windows::Forms::Button());
			this->relay5Button = (gcnew System::Windows::Forms::Button());
			this->relay4Button = (gcnew System::Windows::Forms::Button());
			this->relay3Button = (gcnew System::Windows::Forms::Button());
			this->relay2Button = (gcnew System::Windows::Forms::Button());
			this->relay1Button = (gcnew System::Windows::Forms::Button());
			this->groupBox4 = (gcnew System::Windows::Forms::GroupBox());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->panel4 = (gcnew System::Windows::Forms::Panel());
			this->panel3 = (gcnew System::Windows::Forms::Panel());
			this->panel2 = (gcnew System::Windows::Forms::Panel());
			this->panel1 = (gcnew System::Windows::Forms::Panel());
			this->groupBox5 = (gcnew System::Windows::Forms::GroupBox());
			this->label14 = (gcnew System::Windows::Forms::Label());
			this->label13 = (gcnew System::Windows::Forms::Label());
			this->label12 = (gcnew System::Windows::Forms::Label());
			this->label11 = (gcnew System::Windows::Forms::Label());
			this->label10 = (gcnew System::Windows::Forms::Label());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->progressBar3 = (gcnew System::Windows::Forms::ProgressBar());
			this->progressBar2 = (gcnew System::Windows::Forms::ProgressBar());
			this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
			this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components));
			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
			this->timer2 = (gcnew System::Windows::Forms::Timer(this->components));
			this->timer3 = (gcnew System::Windows::Forms::Timer(this->components));
			this->groupBox1->SuspendLayout();
			this->groupBox2->SuspendLayout();
			this->groupBox3->SuspendLayout();
			this->groupBox4->SuspendLayout();
			this->groupBox5->SuspendLayout();
			this->SuspendLayout();
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->rxTextBox);
			this->groupBox1->Controls->Add(this->label4);
			this->groupBox1->Controls->Add(this->txTextBox);
			this->groupBox1->Controls->Add(this->label3);
			this->groupBox1->Controls->Add(this->addressTextBox);
			this->groupBox1->Controls->Add(this->label2);
			this->groupBox1->Controls->Add(this->baudButton);
			this->groupBox1->Controls->Add(this->openButton);
			this->groupBox1->Controls->Add(this->portTextBox);
			this->groupBox1->Controls->Add(this->label1);
			this->groupBox1->Location = System::Drawing::Point(12, 12);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(254, 77);
			this->groupBox1->TabIndex = 0;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Comms";
			// 
			// rxTextBox
			// 
			this->rxTextBox->Location = System::Drawing::Point(160, 45);
			this->rxTextBox->Name = L"rxTextBox";
			this->rxTextBox->Size = System::Drawing::Size(86, 20);
			this->rxTextBox->TabIndex = 9;
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(129, 48);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(25, 13);
			this->label4->TabIndex = 8;
			this->label4->Text = L"RX:";
			// 
			// txTextBox
			// 
			this->txTextBox->Location = System::Drawing::Point(39, 44);
			this->txTextBox->Name = L"txTextBox";
			this->txTextBox->Size = System::Drawing::Size(86, 20);
			this->txTextBox->TabIndex = 7;
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(9, 48);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(24, 13);
			this->label3->TabIndex = 6;
			this->label3->Text = L"TX:";
			// 
			// addressTextBox
			// 
			this->addressTextBox->Location = System::Drawing::Point(218, 18);
			this->addressTextBox->Name = L"addressTextBox";
			this->addressTextBox->Size = System::Drawing::Size(28, 20);
			this->addressTextBox->TabIndex = 5;
			this->addressTextBox->Text = L"0";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(166, 21);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(48, 13);
			this->label2->TabIndex = 4;
			this->label2->Text = L"Address:";
			// 
			// baudButton
			// 
			this->baudButton->Location = System::Drawing::Point(117, 17);
			this->

Hi Milton, sorry for the late reply, but in the time since, I decided to junk the whole extra class and make the button sync to COM4 straight without the class but I seem to have hit some problems. Here is the button code now

void CzebraDlg::OnBnClickedButton5()
{
	System::IO::Ports::SerialPort ^mySerialPort = gcnew System::IO::Ports::SerialPort("COM4");
	 try
			{
				
			
			if (mySerialPort->IsOpen)
				{
					mySerialPort->Close();
				}
			//mySerialPort->PortName = "COM4"// + IDC_EDIT2->Text;
			mySerialPort->Open();
			}
		catch (Exception ^ex)
			{
			CerrorDlg  cid;  //*** Create an instance of our dialog
			cid.DoModal(); //Display Dialog box
			}	
}

But when I compile it, I seem to have the following errors

1>.\zebraDlg.cpp(19) : error C2039: 'Ports' : is not a member of 'System::IO'
1>.\zebraDlg.cpp(19) : error C2871: 'Ports' : a namespace with this name does not exist
1>.\zebraDlg.cpp(1696) : error C2882: 'System' : illegal use of namespace identifier in expression
1>.\zebraDlg.cpp(1696) : error C2228: left of '.IO' must have class/struct/union
1>.\zebraDlg.cpp(1696) : error C2228: left of '.Ports' must have class/struct/union
1>.\zebraDlg.cpp(1696) : error C2228: left of '.SerialPort' must have class/struct/union
1>.\zebraDlg.cpp(1696) : error C2065: 'mySerialPort' : undeclared identifier
1>.\zebraDlg.cpp(1696) : error C2061: syntax error : identifier 'System'
1>.\zebraDlg.cpp(1701) : error C2227: left of '->IsOpen' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\zebraDlg.cpp(1703) : error C2227: left of '->Close' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\zebraDlg.cpp(1706) : error C2227: left of '->Open' must point to class/struct/union/generic type
1> type is ''unknown-type''

The words in red are the main problem, I think the ones with the '->'s are because of them. Anyway, below are all the includes, maybe I did something wrong there?

#using <system.dll>
#include "System.dll"
#include "stdafx.h"
#include "zebra.h"
#include "zebraDlg.h"
#include <string>
#include <fstream>
#include "windows.h"
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include "usb.h"
#include <setupapi.h>
#include <hidsdi.h>
using namespace System;
using namespace System::IO;
using namespace System::IO::Ports;

Hi Milton, sorry for the late reply, but in the time since, I decided to junk the whole extra class and make the button sync to COM4 straight without the class but I seem to have hit some problems. Here is the button code now

void CzebraDlg::OnBnClickedButton5()
{
	System::IO::Ports::SerialPort ^mySerialPort = gcnew System::IO::Ports::SerialPort("COM4");
	 try
			{
				
			
			if (mySerialPort->IsOpen)
				{
					mySerialPort->Close();
				}
			//mySerialPort->PortName = "COM4"// + IDC_EDIT2->Text;
			mySerialPort->Open();
			}
		catch (Exception ^ex)
			{
			CerrorDlg  cid;  //*** Create an instance of our dialog
			cid.DoModal(); //Display Dialog box
			}	
}

But when I compile it, I seem to have the following errors

1>.\zebraDlg.cpp(19) : error C2039: 'Ports' : is not a member of 'System::IO'
1>.\zebraDlg.cpp(19) : error C2871: 'Ports' : a namespace with this name does not exist
1>.\zebraDlg.cpp(1696) : error C2882: 'System' : illegal use of namespace identifier in expression
1>.\zebraDlg.cpp(1696) : error C2228: left of '.IO' must have class/struct/union
1>.\zebraDlg.cpp(1696) : error C2228: left of '.Ports' must have class/struct/union
1>.\zebraDlg.cpp(1696) : error C2228: left of '.SerialPort' must have class/struct/union
1>.\zebraDlg.cpp(1696) : error C2065: 'mySerialPort' : undeclared identifier
1>.\zebraDlg.cpp(1696) : error C2061: syntax error : identifier 'System'
1>.\zebraDlg.cpp(1701) : error C2227: left of '->IsOpen' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\zebraDlg.cpp(1703) : error C2227: left of '->Close' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.\zebraDlg.cpp(1706) : error C2227: left of '->Open' must point to class/struct/union/generic type
1> type is ''unknown-type''

The words in red are the main problem, I think the ones with the '->'s are because of them. Anyway, below are all the includes, maybe I did something wrong there?

#using <system.dll>
#include "System.dll"
#include "stdafx.h"
#include "zebra.h"
#include "zebraDlg.h"
#include <string>
#include <fstream>
#include "windows.h"
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include "usb.h"
#include <setupapi.h>
#include <hidsdi.h>
using namespace System;
using namespace System::IO;
using namespace System::IO::Ports;
This article has been dead for over six months. Start a new discussion instead.