Burtlancaster
Programmer
Can someone please put me out of my misery! I cannot for the life work the following problem out.
Basically I would like to take an entered value from a TextBox (a string value) and convert it to a float! Simple! I know, but what happens if the user enters a non-digit expression (letters,symbols etc), using the "StrToFloat" method the program will simply return for example "Edit is not a valid floating point value." now what I want to do is catch this Expression and display my own message so I have tried the following code
But the code will never see the catch instead whilst in debug it will display a EConvertError, and then say "Edit1 is not a valid floating point value." So how do I say hang on a minute if it cant convert it then do / say this...
Anyway I'll leave the problem in you capable hands.
Thanks for looking and any input would be much appreciated.
Basically I would like to take an entered value from a TextBox (a string value) and convert it to a float! Simple! I know, but what happens if the user enters a non-digit expression (letters,symbols etc), using the "StrToFloat" method the program will simply return for example "Edit is not a valid floating point value." now what I want to do is catch this Expression and display my own message so I have tried the following code
Code:
//----------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//----------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//----------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//----------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
float EditText=StrToFloat(Edit->Text);
Edit->Text=FloatToStrF(EditText,ffFixed,8,2);
}
catch (...)
{
ShowMessage("non value entered");
}
}
//----------------------------------------------
But the code will never see the catch instead whilst in debug it will display a EConvertError, and then say "Edit1 is not a valid floating point value." So how do I say hang on a minute if it cant convert it then do / say this...
Anyway I'll leave the problem in you capable hands.
Thanks for looking and any input would be much appreciated.