Modeller
January 28th, 2005, 07:26 AM
Hi,
I have two requests regarding to String conversion. For the first one, I am enclosing the part of
C++ code. For the second, please see below right after the first request.
System spesifications :
Compiler : Visual C++ . Net, standart, 2003
Operative system : XP Professional
Request 1 : Conversion from String __gc* to floating point number. The desired input number is a
negative float, e.g. -5000. The following throws "Format Exception"
// the variable depth is declared as follows : float depth;
void depthTextBox_TextChanged(System::Object* sender, System::EventArgs* e)
{
try
{
depth = float(Double::Parse(depthTextBox->Text, System::Globalization::NumberStyles::Float));
if (depth > 0)
{
depthTextBox->set_Text(__box(depth)->ToString());
throw new Exception("Depth is a negative number!");
}
errorProvider->SetError(depthTextBox, "");
}
catch (Exception* ex)
{
// If there is an error, display the text
depthTextBox->set_Text(depthTextBox->Text);
this->errorProvider->SetError(depthTextBox,ex->Message);
}
}
void depthTextBox_Validating(System::Object* sender, System::ComponentModel::CancelEventArgs* e)
{
try
{
if (depthTextBox->Text->Length == 0)
throw new Exception("Depth is required!");
}
catch (Exception* ex)
{
e->Cancel = true;
this->errorProvider->SetError(depthTextBox,ex->Message);
}
}
void depthTextBox_Validated(System::Object* sender, System::EventArgs* e)
{
errorProvider->SetError(depthTextBox, "");
}
What is wrong here?
// ********************** Request 2 ***************************
Conversion from floating number to String __gc* : Say that I have the following
floating point number : -1.2345678 and I want to display only the first two decimal digits of it,
such as -1.23. What is the string format that displays this number?
I thank you very much for your interest.
Regards
Modeller
I have two requests regarding to String conversion. For the first one, I am enclosing the part of
C++ code. For the second, please see below right after the first request.
System spesifications :
Compiler : Visual C++ . Net, standart, 2003
Operative system : XP Professional
Request 1 : Conversion from String __gc* to floating point number. The desired input number is a
negative float, e.g. -5000. The following throws "Format Exception"
// the variable depth is declared as follows : float depth;
void depthTextBox_TextChanged(System::Object* sender, System::EventArgs* e)
{
try
{
depth = float(Double::Parse(depthTextBox->Text, System::Globalization::NumberStyles::Float));
if (depth > 0)
{
depthTextBox->set_Text(__box(depth)->ToString());
throw new Exception("Depth is a negative number!");
}
errorProvider->SetError(depthTextBox, "");
}
catch (Exception* ex)
{
// If there is an error, display the text
depthTextBox->set_Text(depthTextBox->Text);
this->errorProvider->SetError(depthTextBox,ex->Message);
}
}
void depthTextBox_Validating(System::Object* sender, System::ComponentModel::CancelEventArgs* e)
{
try
{
if (depthTextBox->Text->Length == 0)
throw new Exception("Depth is required!");
}
catch (Exception* ex)
{
e->Cancel = true;
this->errorProvider->SetError(depthTextBox,ex->Message);
}
}
void depthTextBox_Validated(System::Object* sender, System::EventArgs* e)
{
errorProvider->SetError(depthTextBox, "");
}
What is wrong here?
// ********************** Request 2 ***************************
Conversion from floating number to String __gc* : Say that I have the following
floating point number : -1.2345678 and I want to display only the first two decimal digits of it,
such as -1.23. What is the string format that displays this number?
I thank you very much for your interest.
Regards
Modeller