How to convert from string to integer?

A

Allen Maki

I am working with MS Visual C++ .net 2003.

With your help, thank you, I am able to take data from the user through a
text box of a form and show the information on label of another form. But I
discovered that the data that I collected was not in such a format by which
I can do simple arithmetic operations on them. I want to be able to
manipulate the collected data arithmetically such as adding and multiplying
them. I would be please if someone can help converting this code in a way
that I can be able to manipulate the collected data arithmetically. In
other words, I would like to have the data in int or double, instead of
string.



Below are snip shots of two classes. Form1 and ResultOut. From the first
class I show the event handler and from the second class I show the
property.





//Form1 :- Form1.h:



public __gc class Form1 : public System::Windows::Forms::Form

{

..

..

..

..



private: System::Void OKBtn_Click(System::Object * sender,
System::EventArgs * e)

{

//Create dialog

ResultOut* box = new ResultOut();



//Fill fill in data



box->Result = Form1::NumInBox->Text;



//Show dialog

if (box->ShowDialog() == DialogResult::OK)

{

box->Result; //get is used

}





};



//Form2:- ResultOut.h:



public __gc class ResultOut : public System::Windows::Forms::Form

{

..

..

..

..

..

..



public:

__property void set_Result(String* n){resultOutLbl->Text = n;}

__property String* get_Result(){return resultOutLbl->Text;}



};
 
E

Earl

I'm gonna guess at what you are asking.

You can convert a string to a number in several different ways. Probably the
best way is to use TryParse, something like the following:

Dim result as boolean
Dim YourDecimal as Decimal

result = Decimal.TryParse(YourString,
Globalization.NumberStyles.AllowDecimalPoint, YourDecimal)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top