Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

textBox & String

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John. S. - 09 Apr 2007 18:17 GMT
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(???);

2) I'd like to display in a loop:
abc 0 def
abc 1 def
abc 2 def
abc 3 def
abc 4 def

What I've found is:
for(int i = 0; i < 5; i++)
  MessageBox::Show(String::Concat("abc ", i.ToString(), " def");

Is there an easier way to display that?
(I mean the Borland way: ShowMessage("abc " + IntToStr(i) + " def"); )

3)I'd like to add multiple lines to a textBox at runtime. The MultiLine
property of the textBox is true.
Line0
Line1
Line2
Line3...
How do I use the textBox1->Lines or textBox1->Lines->Item[i] for this
purpose ?

Thanks...
pvdg42 - 10 Apr 2007 04:12 GMT
> 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).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.