Click to See Complete Forum and Search --> : Getting an int from a TextBox


Nebulous777
August 18th, 2002, 04:24 PM
I am writing a program in VC++.net and I have implemented a TextBox to prompt the user for data. Right now I am trying to read this input from the Text member of the TextBox which is in the form of a System::String _gc. However, what I want is to read this data as an int. Is there a better way to get an int from the user or can I convert from a System::String _gc to an int ?

-Leo

DaRacne Shaitan
September 1st, 2002, 03:13 PM
I know this post is a little delayed, but I just signed up for these forums myself. Have you tried doing atoi() on your string? That should make them an integer, and if you want them to be a float just do atof().

Nebulous777
September 1st, 2002, 08:36 PM
I already tried that, but I get an error as follows:

error C2664: 'atoi' : cannot convert parameter from 'System::String __gc *(void)' to 'const char *'

catlook
September 16th, 2002, 07:19 PM
Here's my deep thought:

Assuming you are using MFC and your text box is in a dialog, go to the class wizard for that dialog class, and then click on the "member variables" tab. At that point you should see a list of controls for your dialog and you can click the "Add Variable" button after you highlight your edit box identifier. Then you should be able to add your new variable and select the data type (CString, int, UINT, etc).

Nebulous777
September 17th, 2002, 04:28 PM
I don't see what the purpose of adding another variable to my dialog would be. I want the user to type into a TextBox and so I need to perform the conversion on the data returned by the TextBox which is of the type:

System::Windows::Forms::TextBox __gc*

Maybe I'm just not looking at the problem from the right angle, but it seems to me that I must find a way to convert the data passed into the TextBox into an integer. In order to do this, I must find a way to convert from a String __gc* to an int. If you think there is another way to get an int from a TextBox, then by all means, please tell me more about your idea.