Board index » cppbuilder » Using Edit box to get numerical value from the user?!!
sam
![]() CBuilder Developer |
sam
![]() CBuilder Developer |
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?!! |
Chris Uzdavinis
![]() CBuilder Developer |
2004-06-02 04:56:27 AM
Re:Using Edit box to get numerical value from the user?!!
"sam" < XXXX@XXXXX.COM >writes:
QuoteI need to use an Edit Box to get numercal input from the user and display it in another Edit Box .I tried this: 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); |
Sam
![]() CBuilder Developer |
2004-06-02 06:22:23 AM
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: {smallsort} |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-06-02 06:36:28 AM
Re:Using Edit box to get numerical value from the user?!!
"Sam" < XXXX@XXXXX.COM >wrote in message
Quotetemp.stock_no = StrToInt(txtStockNo->Text); assignment. Gambit |
sam
![]() CBuilder Developer |
2004-06-02 07:11:49 AM
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 |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2004-06-02 07:39:07 AM
Re:Using Edit box to get numerical value from the user?!!
"sam" < XXXX@XXXXX.COM >wrote in message
Quotetemp.order_no = txtDescription->Text; have to copy the AnsiString contents into the existing array memory, ie: StrPLCopy(temp.description, txtDescription->Text, MAX_DESCRIPTION); Gambit |
Sam
![]() CBuilder Developer |
2004-06-02 03:33:59 PM
Re:Using Edit box to get numerical value from the user?!!
Great Team,
Thanks |