Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, guys! I hope you help me with this.
I have two forms, both with only buttons. I want to make a combined choice between the two.

1) Clicking on certain buttons in Form1 opens Form2 (that's working fine).

2) Clicking on certain buttons in Form2 must open other forms, depending on which buttons I clicked on both forms.

My code:

This is in Form1:
C++
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		 {
		 	 String ^ m_option1 = "1";//Project
			 Form2 ^form2 = gcnew Form2;
	                 form2->Show();
		 }
This is in Form2:
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		{
			String ^ m_option2 = "1";//Add
			String ^ m_choice  = m_option1 + m_option2;
			Form8_add_tutor ^form8_add_tutor = gcnew Form8_add_tutor;
	                form8_add_tutor->Show();
		}
This is the error: m_option1 undeclared identifier.
NOTE: So far, this has given me the least errors. I tried making m_option1 public and it only made it worse.
THANKS IN ADVANCE
Posted
Updated 9-Mar-12 3:17am
v4
Comments
Sergey Alexandrovich Kryukov 9-Mar-12 10:21am    
Do you know what is a variable, scope, visibility, in general?
--SA
Wilmer Lameda 9-Mar-12 19:41pm    
Yes, thank you.

If you want to share data between forms, your best bet is to make put data into static class that both forms can access. (You're going to have to convert the code below to C++.)

C#
public static class Globals
{
    public static string MyString { get; set; }
}
 
Share this answer
 
Comments
Wilmer Lameda 9-Mar-12 9:24am    
I tried that already, only I didn't add the { get; set; } part.
Thank you. I'll give it another shot.
Sergey Alexandrovich Kryukov 9-Mar-12 10:35am    
John, I have an impression that you did not read the question. Did you notice that OP tried to get access to the local (stack) variable from outside? For such person, you advice is no more than a spell... :-)
Please see my answer...
--SA
Wilmer Lameda 11-Mar-12 11:32am    
Mr Simmons, I tried your suggestion and I've done some research; but string variables were giving me a headache, so I switched to integers. Here's my code:
//global_variables.h
ref class VarGlobales
{
public:
void setvalue();
int getvalue();
private:
int myvalue;
int xxx;
};
void VarGlobales::setvalue(int xxx)
{
myvalue = xxx;
return;
}
int VarGlobales::getvalue()
{
int myvalue;
return myvalue;
}
And here's the error I'm getting:
error C2511: 'void VarGlobales::setvalue(int)' : overloaded member function not found in 'VarGlobales'
I've tried to fix it; but then I get different ones. Can you help?
By the way, I added the corresponding #include "global_variables.h" in the main program.
#realJSOP 11-Mar-12 19:15pm    
Your setvalue method prototype doesn't have an argument defined for it.
Wilmer Lameda 12-Mar-12 12:11pm    
Right. Just didn't see it. Thank you.
Please see my comment to the question. I don't think you are ready to do any development at this moment — not just yet. You declare a a variable m_option1, which is a stack variable. Not only it is no accessible out of the scope of the stack frame, if does not even exist on exit of the function. Same of different instance of the same of different class, access modifiers — all that is totally irrelevant.

You even tried to add an access modifiers to it. This is that kind of "engineering" when someone kicks a TV set until it starts showing picture. You have no chance. You should understand every single line you write. In this case, the problem is not any detail of syntax or something. It shows that you have no idea what is a variable and what is a function. No more no less. And I cannot explain it in a short answer. You need to grab a manual and start learning programming from the very beginning, this time with full understanding. Solve simple problems, to get a grip on the code.
As Yoda wrote:
Unlearn what you have learned.
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900