J
Jose Cintron
Hello all. Newbie question here...
I have a program that needs to do 1 of 2 things
1. declare a global System::String (which I think can't be done, because
VS 2005 complains)
2. modify the System::String in one function
An example may be easier to understand... The question is how would I get
the second option to work???
--- First option
// All of my defines go here
#define fnOfFile "test.xml"
#define ErrorFNF 1
#define OK 0
// Global Vars
System::String GlobalString;
namespace ReportGenerator {
public ref class Form1 : public System::Windows::Forms::Form
{
private: int CheckFiles()
{
// If file is in current directory
GlobalString = String::Concat(".\\" + fnOfFile);
// else If file is in parent directory
GlobalString = String::Concat("..\\" + fnOfFile);
// else
return ErrorFNF;
return OK;
}
private: System::Void btnGenerate_Click(System::Object^ sender,
System::EventArgs^ e)
{
// some code here
status = CheckFiles();
}
}
}
--- Second option
// All of my defines go here
#define fnOfFile "test.xml"
#define ErrorFNF 1
#define OK 0
namespace ReportGenerator {
public ref class Form1 : public System::Windows::Forms::Form
{
private: int CheckFiles(System::String^ aString)
{
// If file is in current directory
aString = String::Concat(".\\" + fnOfFile);
// else If file is in parent directory
aString = String::Concat("..\\" + fnOfFile);
// else
return ErrorFNF;
return OK;
}
private: System::Void btnGenerate_Click(System::Object^ sender,
System::EventArgs^ e)
{
System::String FileName = "";
// some code here
status = CheckFiles(FileName);
// Now FileName has the correct location (if the file was found)
}
}
}
I have a program that needs to do 1 of 2 things
1. declare a global System::String (which I think can't be done, because
VS 2005 complains)
2. modify the System::String in one function
An example may be easier to understand... The question is how would I get
the second option to work???
--- First option
// All of my defines go here
#define fnOfFile "test.xml"
#define ErrorFNF 1
#define OK 0
// Global Vars
System::String GlobalString;
namespace ReportGenerator {
public ref class Form1 : public System::Windows::Forms::Form
{
private: int CheckFiles()
{
// If file is in current directory
GlobalString = String::Concat(".\\" + fnOfFile);
// else If file is in parent directory
GlobalString = String::Concat("..\\" + fnOfFile);
// else
return ErrorFNF;
return OK;
}
private: System::Void btnGenerate_Click(System::Object^ sender,
System::EventArgs^ e)
{
// some code here
status = CheckFiles();
}
}
}
--- Second option
// All of my defines go here
#define fnOfFile "test.xml"
#define ErrorFNF 1
#define OK 0
namespace ReportGenerator {
public ref class Form1 : public System::Windows::Forms::Form
{
private: int CheckFiles(System::String^ aString)
{
// If file is in current directory
aString = String::Concat(".\\" + fnOfFile);
// else If file is in parent directory
aString = String::Concat("..\\" + fnOfFile);
// else
return ErrorFNF;
return OK;
}
private: System::Void btnGenerate_Click(System::Object^ sender,
System::EventArgs^ e)
{
System::String FileName = "";
// some code here
status = CheckFiles(FileName);
// Now FileName has the correct location (if the file was found)
}
}
}