Click here to Skip to main content
15,914,160 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Hi can anyone help me if add all the textboxes then convert it to 10%?

here's my textboxes the max input is 20 each of them

What I have tried:

btncalculate
VB
txtQuiz1.text
txtQuiz2.text
txtQuiz3.text
txtQuiz4.text
txtQuiz5.text
txtQuiz6.text
txtResultQuiz.text
Posted
Updated 10-Mar-17 22:13pm
v2

1 solution

Just add those textbox value and divide by the total (120) ? I misread the question earlier, the OP requested VB.NET instead of C# and 10% of the result

VB
txtResultQuiz.Text = (CDbl(Integer.Parse(txtQuiz1.Text) _
+ Integer.Parse(txtQuiz2.Text) _
+ Integer.Parse(txtQuiz3.Text) _
+ Integer.Parse(txtQuiz4.Text) _
+ Integer.Parse(txtQuiz5.Text) _
+ Integer.Parse(txtQuiz6.Text)) * 0.1).ToString()

C#
txtResultQuiz.Text =
               ((double) (int.Parse(txtQuiz1.Text) + int.Parse(txtQuiz2.Text) + int.Parse(txtQuiz3.Text) + int.Parse(txtQuiz4.Text)
                + int.Parse(txtQuiz5.Text) + int.Parse(txtQuiz6.Text)) / 120).ToString("0.00%");
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 10-Mar-17 22:55pm    
Hi Bryian,
the op has tagged VB.Net :) , translated your code to vb
txtResultQuiz.Text = (CType((Integer.Parse(txtQuiz1.Text)  _
            + (Integer.Parse(txtQuiz2.Text)  _
            + (Integer.Parse(txtQuiz3.Text)  _
            + (Integer.Parse(txtQuiz4.Text)  _
            + (Integer.Parse(txtQuiz5.Text) + Integer.Parse(txtQuiz6.Text)))))),Double) / 120).ToString("0.00%")
Bryian Tan 10-Mar-17 23:01pm    
Karthik, thanks, didn't pay attention :)
Karthik_Mahalingam 10-Mar-17 23:03pm    
Welcome :)
Jim Clinton 10-Mar-17 23:18pm    
is that for btncalculate button?

txtResultQuiz.Text = (CType((Integer.Parse(txtQuiz1.Text) _
+ (Integer.Parse(txtQuiz2.Text) _
+ (Integer.Parse(txtQuiz3.Text) _
+ (Integer.Parse(txtQuiz4.Text) _
+ (Integer.Parse(txtQuiz5.Text) + Integer.Parse(txtQuiz6.Text)))))),Double) / 120).ToString("0.00%")
Bryian Tan 10-Mar-17 23:21pm    
yes.

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