473,325 Members | 2,816 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,325 software developers and data experts.

get an integer from a text box.

Is there some way to convert a string which consists of a number(eg. 24) to an integer type? I am trying to get the value from the text property of a text box.

Nov 16 '05 #1
4 9631
int n = int.Parse("24");
int n = int.Parse(TextBox1.Text);
--
Klaus H. Probst, MVP
http://www.vbbox.com/
"owyn" <ow**@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Is there some way to convert a string which consists of a number(eg. 24) to an integer type? I am trying to get the value from the text property of a
text box.

Nov 16 '05 #2
> int n = int.Parse("24");
int n = int.Parse(TextBox1.Text);


Be sure to wrap that code in a try...catch block in case someone enters
invalid data, like this:

try
{
int n = int.Parse("24");
int n = int.Parse(TextBox1.Text);
}
catch (Exception ex)
{
// Do something to indicate TextBox1 does not contain a valid integer
}

You could also trap for the specific exceptions that Parse can throw, which
are FormatException, ArgumentException and OverflowException.

Eric

Nov 16 '05 #3
int num = Convert.ToInt32(textbox1.text);

dont forget to catch exception

--
Shak
(Houston)
"owyn" <ow**@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Is there some way to convert a string which consists of a number(eg. 24) to an integer type? I am trying to get the value from the text property of a
text box.

Nov 16 '05 #4
Hi owyn,

You can look into C# checked and unchecked keywords. It will throw exceptions if string -> int fail to work.

Correct me if i am wrong. Thanks.

--
Regards,
Chua Wen Ching :)
"Shakir Hussain" wrote:
int num = Convert.ToInt32(textbox1.text);

dont forget to catch exception

--
Shak
(Houston)
"owyn" <ow**@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
Is there some way to convert a string which consists of a number(eg. 24)

to an integer type? I am trying to get the value from the text property of a
text box.


Nov 16 '05 #5

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

Similar topics

4
by: FatboyCanteen | last post by:
If I have a textbox, Let use to input a text. I want to check the input text is integer type or no I use isnum() to validate it, but double type also pass the validation. I don't want to use Field...
38
by: Keith | last post by:
I've been reading and looking on the internet - but I just can't fin this. Perhaps I'm approaching this the wrong way - code-wise I'm attempting to learn how "things" work in VBNET by creating...
5
by: poldoj | last post by:
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...
38
by: Maarten | last post by:
hi all, how can i retrieve the type if a value inserted in an inputbox. what i want to do is make shure people only insert an integer type, if they don't they get an error message. ...
6
by: Martin Heuckeroth | last post by:
Hi, We are looking for a way to determine the x and y points of the cursor in a richtext box. We made an VB.NET application with a couple of listboxes and one of them is a richtextlistbox....
3
by: mike | last post by:
I have the following view definition Column | Type | Modifiers ----------------+-----------------------+----------- bcode | character varying(15) | subhead ...
7
by: kangaroo | last post by:
Hello, I have a column of type VARCHAR, storing some generally character data. A few of the values in that column are in fact numbers represented as strings (e.g., "12345"). At some moment I...
5
by: YardDancer | last post by:
Hi all I don't want to use the the Cint() or CDec() or other VB.Net Functions and I dont want to restrict keystrokes in the textbox. I am also using the "strict type semantic" settings that...
10
by: Dave griffiths | last post by:
Hi all Using VB2005 on Vista with a Norwegian locale setup. The test program has 3 textboxes the sum held in txt3. Using the code below, txt2 conversion causes an error when it is left empty....
11
by: cmdolcet69 | last post by:
Public Shared adc_value As word_byte Public Class byte_low_hi Public low_byte As Byte Public high_byte As Byte End Class pmsg(2) = CChar(adc_value.word16.high_byte)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.