string and integer

P

poldoj

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
 
C

Cor Ligthert

Poldoj,

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

I hope this helps,

Cor
 
S

Shiva

Try: hold_sum += Int32.Parse (textbox.Text)

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

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
 
G

Guest

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

Guest

Sorry I missed the addition part of the question

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

poldoj

I tried hold_sum += Int32.Parse (textbox.Text)
and it worked!
Thank you so much
I will try also the directcast function ^_^
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top