Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello friend,

I am using this code to count number

C#
int Startcount = Convert.ToInt32(TextBox1.Text);
int Endcount = Convert.ToInt32(TextBox2.Text);
int count = 0;
for (int i = Startcount; i < Endcount; i++)
{
    count = i;
}
label.Text = "Number: " + count.ToString();

There is 0 value in textbox1 and TextBox2 value is 100000000000 this

i am gating error when my TextBox2.text = 100000000000

i want to count number based on set in TextBox1 to TextBox2
please give me soluton how can i solve cont any nuber lent from TextBox1 to TextBox2
Thank you
Posted
Updated 9-Feb-13 23:54pm
v4
Comments
Alan N 10-Feb-13 6:02am    
When asking a question it is important that you include all relevant information.
In this case we need to know what exception you see and on which line on which it occurs.
bikramjeet.sm 10-Feb-13 7:21am    
this is a error with this current code Value was either too large or too small for an Int32. and when i use Convert.ToInt64 then i will get Error Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
Alan N 10-Feb-13 8:35am    
What I was trying to get you to say was something like

I am getting a System.OverflowException with the message "Value was either too large or too small for an Int32." on the line

int Endcount = Convert.ToInt32(TextBox2.Text);

That error happened at run time and OriginalGriff has explained why.

Now you have a compile time error as you have written something like

int Endcount = Convert.ToInt64(TextBox2.Text);

and the compiler knows that an Int64 will not fit into an int (Int32). The correct line would be

long Endcount = Convert.ToInt64(TextBox2.Text);

Always, always post your code along with the exact error message and the line where it occurs. Otherwise the people who want to help you are guessing.
bikramjeet.sm 10-Feb-13 13:02pm    
yes it is

1 solution

The largest number you can hold in an Int32 is:
C#
2,147,483,647
So your value of:
C#
100,000,000,000
is way, way too big!

Change your Convert.ToInt32 to Convert.ToInt64 calls instead, and use long values instead of int.
 
Share this answer
 
Comments
bikramjeet.sm 10-Feb-13 7:35am    
this is a error with this current code Value was either too large or too small for an Int32. and when i use Convert.ToInt64 then i will get Error Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
OriginalGriff 10-Feb-13 7:41am    
That is why I said "and use long values instead of int."

An int is an Int32, a long is an Int64. You cannot fit any value greater than 2,147,483,647 in any Int32.
bikramjeet.sm 10-Feb-13 7:58am    
i am doing this same what you asked but still error
OriginalGriff 10-Feb-13 8:13am    
I bet you aren't! :laugh:
If you are getting the error message "Value was either too large or too small for an Int32" then you are still trying to use an int or Int32 value - you can't put that big a number in it.
Try and copy'n'paste your code fragment here - I'll see if I can spot what you have missed.
bikramjeet.sm 10-Feb-13 8:32am    
What did i have missed in it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900