i have a problem to sum up the value.
for example:
in my richtextbox1:
0.94
0.83
1.67
0.50
0.67
1.25
0.98

now i wan to total up the value.
if the value is less than 1 , then total is 5.
if the value is greater than 1, then total is 2.
below are my coding, but cannot work.

``````  int count = 0;

double liftV = richTextBox24.Lines.Length;

if (liftV <1.00)
{
count++;

}
textBox5.Text=count.ToString();
``````

hope someone can help me..

Edited by Nick Evan: Fixed formatting

3
Contributors
11
Replies
12
Views
6 Years
Discussion Span
Last Post by ashley11
Featured Replies
• 1

This Code is Working Fine.... Check the input you are giving in the richTextBox1 [CODE] double sum = 0; int length = richTextBox1.Lines.Length, totalGreater = 0, totalSmaller = 0; for (int i = 0; i < length; i++) { //sum+=Double.Parse(richTextBox1.Lines[i]); if (Double.Parse( richTextBox1.Lines[i]) >= 1) totalGreater++; else totalSmaller++; } MessageBox.Show("Total …

Code to sum up

``````//Your Code
double sum=0;
int length=richTextBox1.Lines.Length;
for(int i=0;i<length;i++)
{
sum+=Double.Parse(richTextBox1.Lines[i]);
}
if(sum<1)
{
}
else
{
}

Edited by abelLazm: n/a

``````//Your Code
double sum=0;
int length=richTextBox1.Lines.Length, totalGreater=0, totalsmaller=0;
for(int i=0;i<length;i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if(Double.Parse(richTextBox1.Lines[i])>=1)
totalGreater++;
else
totalSmaller++;

}
MessageBox("Total values less than 1 are:"+totalSmaller+"\n Total values greater than equal to 1 are:"+totalGreater);

i had try your code, but it show me a error which is input string was not in a correct format.
may i know any wrong that i did?

This Code is Working Fine.... Check the input you are giving in the richTextBox1

``````double sum = 0;
int length =   richTextBox1.Lines.Length, totalGreater = 0, totalSmaller = 0;
for (int i = 0; i < length; i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if (Double.Parse( richTextBox1.Lines[i]) >= 1)
totalGreater++;
else
totalSmaller++;

}
MessageBox.Show("Total values less than 1 are:" + totalSmaller + "\n Total values greater than equal to 1 are:" + totalGreater);

Edited by abelLazm: n/a

``````string b = txtTotalItems.Text;
double tt = Double.Parse(b);
double a;
double conf;
double lift;

richTextBox23.Clear();
richTextBox24.Clear();
richTextBox20.Clear();

for (int i = 0; i < list8.Count; i++)
{
double wee = list8[i];
a = (wee / tt) * 100;
richTextBox3.AppendText(string.Format("{0:n2}", a) + "\n");

double SuppA = list9[i];
conf = a / (SuppA / tt);
richTextBox2.AppendText(string.Format("{0:n2}", conf) + "\n");

double SuppB = list10[i];
lift = conf / (SuppB / tt) / 100;
richTextBox1.AppendText(string.Format("{0:n2}", lift) + "\n");``````

code above are my calculation part. now i wan to sum up the total in the rich textBox1.
when i try your coding, then show me the error which i mentioned just now. how to i correct it?

can you please tell where you want to add the above mentioned code?

``````string b = txtTotalItems.Text;
double tt = Double.Parse(b);
double a;
double conf;
double lift;

richTextBox23.Clear();
richTextBox24.Clear();
richTextBox20.Clear();

for (int i = 0; i < list8.Count; i++)
{
double wee = list8[i];
a = (wee / tt) * 100;
richTextBox3.AppendText(string.Format("{0:n2}", a) + "\n");

double SuppA = list9[i];
conf = a / (SuppA / tt);

richTextBox2.AppendText(string.Format("{0:n2}", conf) + "\n");

double SuppB = list10[i];
lift = conf / (SuppB / tt) / 100;

richTextBox1.AppendText(string.Format("{0:n2}", lift) + "\n");
}

double sum = 0;
int length = richTextBox24.Lines.Length, totalGreater = 0, totalSmaller = 0;
for (int i = 0; i < length; i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if (Double.Parse(richTextBox24.Lines[i]) >= 1)
totalGreater++;
else
totalSmaller++;

}
MessageBox.Show("Total values less than 1 are:" + totalSmaller + "\n Total values greater than equal to 1 are:" + totalGreater);
}``````

may i know any mistake with it?

``````string b = txtTotalItems.Text;
double tt = Double.Parse(b);
double a;
double conf;
double lift;

richTextBox23.Clear();
richTextBox24.Clear();
richTextBox20.Clear();

for (int i = 0; i < list8.Count; i++)
{
double wee = list8[i];
a = (wee / tt) * 100;
richTextBox3.AppendText(string.Format("{0:n2}", a) + "\n");

double SuppA = list9[i];
conf = a / (SuppA / tt);

richTextBox2.AppendText(string.Format("{0:n2}", conf) + "\n");

double SuppB = list10[i];
lift = conf / (SuppB / tt) / 100;

richTextBox1.AppendText(string.Format("{0:n2}", lift) + "\n");
}

double sum = 0;
int length = richTextBox1.Lines.Length, totalGreater = 0, totalSmaller = 0;
for (int i = 0; i < length; i++)
{
//sum+=Double.Parse(richTextBox1.Lines[i]);
if (Double.Parse(richTextBox1.Lines[i]) >= 1)
totalGreater++;
else
totalSmaller++;

}
MessageBox.Show("Total values less than 1 are:" + totalSmaller + "\n Total values greater than equal to 1 are:" + totalGreater);
}``````

may i know any mistake with it?

in line# 30 run the loop to i<length-1 because you append "\n" at the end that is why your last item in the richTextBox1 is an empty string which is causing error

Apart from the Point said by abelLazm remaining all is fine, i checked it out.

thanks. i get it.