Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Concatenation with edit boxes

Status
Not open for further replies.

bd02eagle

Programmer
Jul 7, 2006
15
0
0
US
I'm using two edit boxes in Borland C++ and I'm trying to get the values of the two boxes to be calculated and displayed on the screen by way a go button that I click. I tried writing &Edit1+ Edit2 in the OnClick section of the event handler for the go button but this is not working. Please help me resolve this situation.

Thanks
 
You need to call TEdit's Text property. The text property sends the string back as an AnsiString. Try any of the following:
Code:
// The step by step way
AnsiString Edit1Str = Edit1->Text;
AnsiString Edit2Str = Edit2->Text;
AnsiString Edit3Str = Edit1Str + " " + Edit2Str;
Edit3->Text = Edit3Str;

// The two step way
AnsiString EditStr = Edit1->Text + " " + Edit2->Text;
Edit3->Text = EditStr;

// The one step way
Edit3->Text = Edit1->Text + " " + Edit2->Text;

Which way you do it depends on the steps you need between. For example, if you needed to convert the strings to a numbers, I would go with the first method and add the conversion routines before setting Edit3Str.

James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
The first step works great for string concatenation. However, I guess I worded my problem wrong. What I was looking for was not the concatentation of the numbers as much as I was actually lookin for the addition of the two (ie. if L1 =1 and L2 = 2, the answer I was expecting would be 3 instead of 12). I'll have to do more research on the conversion routine that you mentioned earlier for convert strings into numbers but thanks for the help so far. Any more tips on what else I could use?
 
To convert the strings into integers, use the ToInt() method of the Text property of the Edit component.
 
Thanks for the help guys. The function works great!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top