473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

textBox & String

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...

Apr 9 '07 #1
4 2186

"John. S." <in*****@invalid.comwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
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.
Apr 10 '07 #2

"pvdg42" <pv****@newsgroups.nospamwrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
>
"John. S." <in*****@invalid.comwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
>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.
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.
Apr 10 '07 #3
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.
calling
System::Int::Parse(textBox1->text);
gives a compile error:
error C2039: 'Int' : is not a member of 'System'

???
Apr 11 '07 #4

"John. S." <in*****@invalid.comwrote in message
news:e6*************@TK2MSFTNGP06.phx.gbl...
>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.

calling
System::Int::Parse(textBox1->text);
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).
Apr 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tomomichi Amano | last post by:
Hello. I was wondering how to paste-copy-cut-delete at a SELECTED SPOT in a textBox. Thanks in advance.
1
by: Tomomichi Amano | last post by:
Could some one tell me how I can seach and replace only one word in a textBox (THE FIRST WORD THAT COMES AFTER THE CURSOR). I already know how to replace ALL , but I don't know how to REPLACE one,...
2
by: RobRich | last post by:
I'm trying to figure out the best way to accomplish a task. I need to calculate the numerical values from about 300+ textboxes. Basiclly I have an application that users input checks and credit...
0
by: rbutch | last post by:
hey guys got a question. im trying to bind a textbox "at runtime". im creating the conn string, dataset, dataAdapter etc dynamically. and it keeps erroring out. <asp:TextBox ID="txtDay1"...
5
by: velu | last post by:
Problem in getting value from textbox & radiobuttonlist to a valuable inside a datagid. I want to insert a record into a table thru datagrid. Here is the code (see below) Private Sub...
1
by: VB Programmer | last post by:
With HTML, how do I get the value of a textbox in an ItemTemplate column within a datagrid? Simple shopping cart. For each row: 1 column is a textbox where they can enter the quantity. 1...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
1
by: Ivan Jericevich | last post by:
I want to join the text from a combobox and a textbox preferably with a space between, as string
17
by: AWW | last post by:
Using Textbox.Text = "123" & CStr(13) & "456" I expect 2 lines on the screen but get 1 line with 13 in it. It worked once in a RichTextBox but then stopped. I just want to display aligned tabular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.