Click here to Skip to main content
13,049,233 members (63,395 online)
Rate this:
Please Sign up or sign in to vote.
See more: (untagged)
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:
#pragma endregion
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
		 	 String ^ m_option1 = "1";//Project
			 Form2 ^form2 = gcnew Form2;
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;
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.
Posted 9-Mar-12 3:13am
Updated 9-Mar-12 3:17am
SAKryukov 9-Mar-12 10:21am
Do you know what is a variable, scope, visibility, in general?
Wilmer Lameda 9-Mar-12 19:41pm
Yes, thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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++.)

public static class Globals
    public static string MyString { get; set; }
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.
SAKryukov 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...
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:
ref class VarGlobales
void setvalue();
int getvalue();
int myvalue;
int xxx;
void VarGlobales::setvalue(int xxx)
myvalue = xxx;
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.
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 9 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100