Hi D.Bane!
Labels are read only... Why are numbers entered in them?
Anyways, both EditBox::contents and Label::text are String/char *, so you can use either the same way to convert it to a double. Both strings returned by the controls' properties are ensured to be valid string and not to be null, so I'm a bit puzzled how you got it to crash.
And again this can be done exactly like in regular C.
atof() and
strtod() both work, the latter being preferred.
sprintf however is for the reverse operation (it's used e.g. to make a string representation of a number).
sscanf() however, will also work, but I would advise against using it.
FloatFromString in the Ecere library should work as well.
I will show you some code how to do it with each of the functions:
Code: Select all
//Suppose you have an edit box with your string:
EditBox editBox { /* I'm omitting its properties for the sake of the example */ };
String s = editBox.contents;
double d;
// Using atof
d = atof(s);
// Using strtod
d = strtod(s, null);
// Using FloatFromString
d = FloatFromString(s);
// Using sscanf (This one might depend on the platform... Maybe "%lf" doesn't work for Windows)
sscanf(s, "%lf", &d);
// This is also supposed to work, but broken at the moment :(
d.OnGetDataFromString(s);
Ah I forgot to suggest you can also use a DataBox to have the user enter numbers.
You give it the address of a variable of your data type of choice inside your form, and it will automatically update it for you.
Code: Select all
class MyForm : Window
{
size = { 640, 480 };
hasClose = true;
SavingDataBox control
{
this, size = { 80, 20 }, position = { 10, 10 };
type = class(double), data = &d;
};
double d;
}
It requires a bit of clean up though... DataBox vs SavingDataBox... (The latter might be renamed to 'DataBox' and DataBox to something else to be used internally)
Hope this helps!
Jerome