user1576628
user1576628

Reputation: 800

syntax error : missing ';' before '.'

I'm unfamiliar with visual C++, so I compiled a simple program using the .NET framework to find my way around it.

#pragma once


namespace Netattempt2 {

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::TextBox^  txtbxUsername;
private: System::Windows::Forms::Button^  btnClick;
protected: 

protected: 

private: System::Windows::Forms::Label^  label1;

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

#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->txtbxUsername = (gcnew System::Windows::Forms::TextBox());
        this->btnClick = (gcnew System::Windows::Forms::Button());
        this->label1 = (gcnew System::Windows::Forms::Label());
        this->SuspendLayout();
        // 
        // txtbxUsername
        // 
        this->txtbxUsername->Location = System::Drawing::Point(94, 17);
        this->txtbxUsername->Name = L"txtbxUsername";
        this->txtbxUsername->Size = System::Drawing::Size(174, 20);
        this->txtbxUsername->TabIndex = 0;
        // 
        // btnClick
        // 
        this->btnClick->Location = System::Drawing::Point(204, 43);
        this->btnClick->Name = L"btnClick";
        this->btnClick->Size = System::Drawing::Size(64, 23);
        this->btnClick->TabIndex = 1;
        this->btnClick->Text = L"Click Me!";
        this->btnClick->UseVisualStyleBackColor = true;
        this->btnClick->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
        // 
        // label1
        // 
        this->label1->AutoSize = true;
        this->label1->Location = System::Drawing::Point(12, 20);
        this->label1->Name = L"label1";
        this->label1->Size = System::Drawing::Size(76, 13);
        this->label1->TabIndex = 2;
        this->label1->Text = L"Enter name -->";
        this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(284, 73);
        this->Controls->Add(this->label1);
        this->Controls->Add(this->btnClick);
        this->Controls->Add(this->txtbxUsername);
        this->Name = L"Form1";
        this->Text = L"Hello World!";
        this->ResumeLayout(false);
        this->PerformLayout();

    }
#pragma endregion
private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e) {
         }
private: System::Void btnClick_Click(System::Object^  sender, System::EventArgs^  e) {
             MessageBox.Show("Welcome to windows " + txtbxUsername.Text, "Hi there...");
         }
};
}

And this line:

MessageBox.Show("Welcome to windows " + txtbxUsername.Text, "Hi there...");

Returns this error:

Form1.h(114) : error C2143: syntax error : missing ';' before '.'

Taking out the line allows the program to compile, but the message box is more or less necessary to the program.

Does anyone know what's going wrong here?

Upvotes: 1

Views: 917

Answers (1)

Steve
Steve

Reputation: 216293

Change to

MessageBox::Show("Welcome to windows " + txtbxUsername->Text, "Hi there..."); 
          ^^                                          ^^

Upvotes: 4

Related Questions