> Hi,
>
> 1) How can I convert a Text property (textBox1->Text) or a String to an
> integer?
> (There is a "ToInt32()" member function but I couldn't
> use it. int i = textBox1->Text.ToInt32(???);
Addressing your first question,
http://msdn2.microsoft.com/en-us/library/sf1aw27b.aspx
Note that you must pass the string to be converted as the argument and that
the return type is int.
Ben Voigt - 10 Apr 2007 14:38 GMT
>> Hi,
>>
[quoted text clipped - 9 lines]
> Note that you must pass the string to be converted as the argument and
> that the return type is int.
Oh yuck. What's the point of having namespaces and classes if you throw
everything into one huge "Convert" mess.
Use either System::Int::Parse or System::Int::TryParse:
int i;
try {
i = System::Int::Parse(textBox1->Text);
}
catch (FormatException^ e) {
// not a valid number
}
or
int i;
if (!System::Int::TryParse(textBox1->Text, i)) {
// not a valid number
}
The second one is more efficient unless the frequency of bad inputs is very
very very low.
John. S. - 11 Apr 2007 12:45 GMT
> Use either System::Int::Parse or System::Int::TryParse:
>
[quoted text clipped - 15 lines]
> The second one is more efficient unless the frequency of bad inputs is
> very very very low.
calling
System::Int::Parse(textBox1->text);
gives a compile error:
error C2039: 'Int' : is not a member of 'System'
???
Ben Voigt - 11 Apr 2007 14:08 GMT
>> Use either System::Int::Parse or System::Int::TryParse:
>>
[quoted text clipped - 20 lines]
> gives a compile error:
> error C2039: 'Int' : is not a member of 'System'
Sorry, it's Int32 (or Int16 or Int64 or UInt32 or ..., but Int32 corresponds
to C++'s int).