Answered # problem in total up the value

abelLazm 183 abelLazm 183 Discussion Starter ashley11 Featured Reply abelLazm 183 Discussion Starter ashley11 Discussion Starter ashley11 Discussion Starter ashley11 abelLazm 183 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

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 3 Years Ago by Nick Evan*: Fixed formatting

0

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)
{
//Your Code
}
else
{
//Your Code
}
//Your Code
```

*Edited 5 Years Ago by abelLazm*: n/a

0

```
//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);
//Your Code
```

0

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?

1

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);
//Your Code
```

*Edited 5 Years Ago by abelLazm*: n/a

0

```
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?

0

```
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?

0

```
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?

0

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

This question has already been answered. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...