How to convert from string to integer?

  • Thread starter Thread starter Allen Maki
  • Start date Start date
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;}



};
 
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)
 
Back
Top