Search code examples
winformsc++-cli

MyForm2: undeclared identifier


I've been strugling with this error for a while now.

I'm trying to implement a log in to an ATM system and I'm trying to connect it to a database as well. But when I try to run it, shows up 144 errors that are all the same:

'MyForm2': is not a member of 'jiji'

'MyForm2': undeclared identifier

Syntax error: missing ';' before identifier 'f2'

'f2':undeclared identifier

I honestly don't know why is this happening. I've tried to include MyForm2.h in the main code but nothing changes.

Here I leve the piece of code that is nearly the same for all my 7 forms ( except the 2nd that is the one that is giving the error I think)

MyForm.h:

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    
        try {
            String^ User = textBox1->Text;
            String^ Pwd = textBox2->Text;
            int AN = Int32::Parse(textBox3->Text);

            String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
            MySqlConnection^ con = gcnew MySqlConnection(constr);

            MySqlDataAdapter^ da = gcnew MySqlDataAdapter("Select AccountNum from Userinfo WHERE AccountNum = '" + AN + "'", con);
            DataTable^ dt = gcnew DataTable();
            da->Fill(dt);

            if (dt->Rows->Count >= 1) {
                MySqlCommand^ cmd = gcnew MySqlCommand("insert into Db values (" + AN + ") ", con);

                con->Open();
                MySqlDataReader^ dr = cmd->ExecuteReader();
                con->Close();

                try {
                    this->Hide();
                    jiji::MyForm2 f2;
                    f2.ShowDialog();
                    this->Show();
                }
                finally {
                    this->Close();
                }
            }
            else {
                MessageBox::Show("User does not exist, try again");
            }
        }
        catch (Exception^ e) {
            MessageBox::Show(e->Message);
        }
    }

By the way AN is the Account number.

The MyForm2.h code is the same over and over again except for the ending.

MyForm2.h:

//Extract money 
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    
        try {
            this->Hide();
            jiji::MyForm3 f3;
            f3.ShowDialog();
            this->Show();
        }
        finally {
            this->Close();
        }
    }
    
           //Insert Money
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
    
        try {
            this->Hide();
            jiji::MyForm4 f4;
            f4.ShowDialog();
            this->Show();
        }
        finally {
            this->Close();
        }
    }
    
           //Transfer
    private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
    
        try {
            this->Hide();
            jiji::MyForm5 f5;
            f5.ShowDialog();
            this->Show();
        }
        finally {
            this->Close();
        }
    }
    
           //Check Amount
    private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
    
        try {
            this->Hide();
            jiji::MyForm6 f6;
            f6.ShowDialog();
            this->Show();
        }
        finally {
            this->Close();
        }
    }
    
           //Reload phone
    private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
    
        try {
            this->Hide();
            jiji::MyForm7 f7;
            f7.ShowDialog();
            this->Show();
        }
        finally {
            this->Close();
        }
    }

           //Exit
    private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
        try {
            String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=visualcppdb";
            MySqlConnection^ con = gcnew MySqlConnection(constr);

            MySqlCommand^ cmd = gcnew MySqlCommand("TRUNCATE Db ", con);

            con->Open();
            MySqlDataReader^ dr = cmd->ExecuteReader();
            con->Close();

        }
        catch (Exception^ e) {
            MessageBox::Show(e->Message);
        }
        finally {
            this->Close();
        }
    }

Solution

  • Perhaps you aren't including MyForm2.h in a context MyForm.h can access?

    Maybe look into how to declare a namespace and how to include headers, e.g. Creating a C++ namespace in header and source (cpp)

    What happens if you inline the MyForm2 class definition into MyForm so you guarantee it is accessible?