By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,757 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,757 IT Pros & Developers. It's quick & easy.

string and integer

P: n/a
Hi all, I have a simple question. I must adding the content of a textbox,
that is actually a string to a variable that his datatype is an integer.
Example, I declare a public integer variable then I retrive a textbox.text
value that is a string but is a number.(hold_text=textbox.text) hold text is
"5".
Then I must add 5 to my public variable.

public hold_sum as integer
----
hold_sum += textbox.text

Naturally I cant do this, I have tried the Cint and Ctype functions without
success. Can someone help me? Thanks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Poldoj,

Strange, this should work
public hold_sum as integer
hold_sum += Cint(textbox.text)

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
Try: hold_sum += Int32.Parse (textbox.Text)

If the textbox text contains non-numeric characters, exception will be
thrown.

"poldoj" <po********@gmail.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
Hi all, I have a simple question. I must adding the content of a textbox,
that is actually a string to a variable that his datatype is an integer.
Example, I declare a public integer variable then I retrive a textbox.text
value that is a string but is a number.(hold_text=textbox.text) hold text is
"5".
Then I must add 5 to my public variable.

public hold_sum as integer
----
hold_sum += textbox.text

Naturally I cant do this, I have tried the Cint and Ctype functions without
success. Can someone help me? Thanks

Nov 21 '05 #3

P: n/a
Hi,

If you know that the Text in the textbox contains an integer value then you
can do the following:

Public varx as integer
varx = DirectCast(MyTextBox.Text,System.Integer)

I would recommend validating the textbox first to check it contains/accepts
an integer: which can be done in many ways.

"poldoj" wrote:
Hi all, I have a simple question. I must adding the content of a textbox,
that is actually a string to a variable that his datatype is an integer.
Example, I declare a public integer variable then I retrive a textbox.text
value that is a string but is a number.(hold_text=textbox.text) hold text is
"5".
Then I must add 5 to my public variable.

public hold_sum as integer
----
hold_sum += textbox.text

Naturally I cant do this, I have tried the Cint and Ctype functions without
success. Can someone help me? Thanks

Nov 21 '05 #4

P: n/a
Sorry I missed the addition part of the question

Public varx as integer
varx += DirectCast(MyTextBox.Text,System.Integer)

"Richard Bond" wrote:
Hi,

If you know that the Text in the textbox contains an integer value then you
can do the following:

Public varx as integer
varx = DirectCast(MyTextBox.Text,System.Integer)

I would recommend validating the textbox first to check it contains/accepts
an integer: which can be done in many ways.

"poldoj" wrote:
Hi all, I have a simple question. I must adding the content of a textbox,
that is actually a string to a variable that his datatype is an integer.
Example, I declare a public integer variable then I retrive a textbox.text
value that is a string but is a number.(hold_text=textbox.text) hold text is
"5".
Then I must add 5 to my public variable.

public hold_sum as integer
----
hold_sum += textbox.text

Naturally I cant do this, I have tried the Cint and Ctype functions without
success. Can someone help me? Thanks

Nov 21 '05 #5

P: n/a
I tried hold_sum += Int32.Parse (textbox.Text)
and it worked!
Thank you so much
I will try also the directcast function ^_^
"Shiva" <sh******@online.excite.com> ha scritto nel messaggio
news:ui**************@TK2MSFTNGP09.phx.gbl...
Try: hold_sum += Int32.Parse (textbox.Text)

If the textbox text contains non-numeric characters, exception will be
thrown.

"poldoj" <po********@gmail.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
Hi all, I have a simple question. I must adding the content of a textbox,
that is actually a string to a variable that his datatype is an integer.
Example, I declare a public integer variable then I retrive a textbox.text
value that is a string but is a number.(hold_text=textbox.text) hold text
is
"5".
Then I must add 5 to my public variable.

public hold_sum as integer
----
hold_sum += textbox.text

Naturally I cant do this, I have tried the Cint and Ctype functions
without
success. Can someone help me? Thanks

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.