Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I make a Global Variable?

Status
Not open for further replies.

nytyme

Programmer
Jan 8, 2001
19
US
i used the MFC Exe Dialog Wizard to create a program.

i want to set a variable and then use a MessageBox to pop it up for me.

I tried to set a Global variable by placing it in one of the generated Header files, but it says it tries to create it multiple times. i tried to static it, but it won't take a value now.

how can i create a global variable?
please provide an example with the answer and specific location where to place the definition.
i tried placing it in the STDAFX.H as well and that failed.

thanks,
NyTyme
 
a) you shouldn't write into StdAfx.
b) declare the variable static in the headerfile.
in MyClass declare CString static MyVar.
initialize the variable in the cpp-file outside any
methode:
CString MyClass::MyVar = "anything you want";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top