Board index » cppbuilder » Using Edit box to get numerical value from the user?!!

Using Edit box to get numerical value from the user?!!


2004-06-02 03:17:09 AM
cppbuilder39
I need to use an Edit Box to get numercal input from the user and display it in another Edit Box .I tried this:
int x;
x = Edit1->Text;
Edit2->Text = x;
But didn't work, any help appritiated?!!
 
 

Re:Using Edit box to get numerical value from the user?!!

"sam" < XXXX@XXXXX.COM >writes:
Quote
I need to use an Edit Box to get numercal input from the user and display it in another Edit Box .I tried this:

int x;
x = Edit1->Text;
Edit2->Text = x;

But didn't work, any help appritiated?!!
Q: why do you want to
1) take a string
2) convert it to integer
3) convert it back to string
4) assign string to the Edit2 component
... when you could simply do steps 1 and 2? Since you're not
validating that the data in Edit1->Text really is a number, this is
no different:
Edit2->Text = Edit1->Text;
If you want some validation, you can just use the StrToInt
function, which throws an exception if the format is bad.
Edit1->Text.StrToInt(); // ignore result, this is just validation
Edit2->Text = Edit1->Text;
--
Chris (TeamB);
 

Re:Using Edit box to get numerical value from the user?!!

Thanks Chris your advice in its place
However the case, I am using functions and files written in C-languge, here is my structure:
//From c file:
struct RECORD{
int stock_no;
char description[MAX_DESCRIPTION];
}
And this is how I hadd-code to get the input from the user:
//From the form:
temp.stock_no = StrToInt(txtStockNo->Text);
text = txtDescription->Text;
the first line worked fine getting result, the secind one not getting any result.
Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
"sam" < XXXX@XXXXX.COM >writes:

>I need to use an Edit Box to get numercal input from the user and display it in another Edit Box .I tried this:
>
>int x;
>x = Edit1->Text;
>Edit2->Text = x;
>
>But didn't work, any help appritiated?!!

Q: why do you want to
1) take a string
2) convert it to integer
3) convert it back to string
4) assign string to the Edit2 component

... when you could simply do steps 1 and 2? Since you're not
validating that the data in Edit1->Text really is a number, this is
no different:

Edit2->Text = Edit1->Text;

If you want some validation, you can just use the StrToInt
function, which throws an exception if the format is bad.

Edit1->Text.StrToInt(); // ignore result, this is just validation
Edit2->Text = Edit1->Text;

--
Chris (TeamB);
 

{smallsort}

Re:Using Edit box to get numerical value from the user?!!

"Sam" < XXXX@XXXXX.COM >wrote in message
Quote
temp.stock_no = StrToInt(txtStockNo->Text);
text = txtDescription->Text;

the first line worked fine getting result, the secind one not getting any
result.
You did not show what 'text' is, or how it is being used after the
assignment.
Gambit
 

Re:Using Edit box to get numerical value from the user?!!

Sorry mate it wae my fault. Actually the lines as following:
temp.stock_no = StrToInt(txtStockNo->Text);
temp.order_no = txtDescription->Text;
So there is no text variable had been declared...
I keep getting an error:
[C++ Error] MainForm.cpp(96): E2277 Lvalue required
 

Re:Using Edit box to get numerical value from the user?!!

"sam" < XXXX@XXXXX.COM >wrote in message
Quote
temp.order_no = txtDescription->Text;
Assuming you mean "description" and not "order_no", then you are trying to
assign an AnsiString to a char[] array directly. You can't do that. You
have to copy the AnsiString contents into the existing array memory, ie:
StrPLCopy(temp.description, txtDescription->Text, MAX_DESCRIPTION);
Gambit
 

Re:Using Edit box to get numerical value from the user?!!

Great Team,
Thanks