Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

Working with percentages

$
0
0
Im working on an app that requires us to use check boxes to calculate a total grade depending on input from user. easier to explain if i just post my work so far. (its flawed but im getting it little by little)
My main question as of right now is how do i get a number that is input into a text box to be read by the program as a percentage or even just a decimal? For example when a user inputs 80, the program needs to read it as .80 in order to do the correct math. I know how to make something come out as a percentage ex. percentageLabel.Text = String.Format("{0:P}", endTotal) but not for something to go in as a percentage/ decimal.


Secondly my math is coming out wrong instead of just using the items checked to come out with the percentage you have, it is using all of the check box text boxes so my percentages are all off

Here is the visual design.
Name:  gradecalculator design.png
Views: 56
Size:  125.5 KB

Code:

Public Class GradeCalculator

    Private Sub calculateButton_Click(sender As System.Object, e As System.EventArgs) Handles calculateButton.Click
        'declare variables and constants
        Const EXAM1WV As Double = 0.2
        Const EXAM2WV As Double = 0.3
        Const LAB2WV As Double = 0.05
        Const LAB3WV As Double = 0.1
        Const LAB4WV As Double = 0.1
        Const LAB5WV As Double = 0.1
        Const FINALWV As Double = 0.15
        Dim lab2 As Double
        Dim lab3 As Double
        Dim lab4 As Double
        Dim lab5 As Double
        Dim exam1 As Double
        Dim exam2 As Double
        Dim finalProject As Double
        Dim total As Double
        Dim totalWv As Double
        Dim endTotal As Double


        If lab2CheckBox.Checked = True Then _
            lab2 = Val(lab2TextBox.Text) * LAB2WV
        total += lab2

        If lab3CheckBox.Checked = True Then _
            lab3 = Val(lab3TextBox.Text) * LAB3WV
        total += lab3


        If lab4CheckBox.Checked = True Then _
            lab4 = Val(lab4TextBox.Text) * LAB4WV
        total += lab4

        If lab5CheckBox.Checked = True Then _
            lab5 = Val(lab5TextBox.Text) * LAB5WV
        total += lab5

        If exam1CheckBox.Checked = True Then _
            exam1 = Val(exam1TextBox.Text) * EXAM1WV
        total += exam1

        If exam2CheckBox.Checked = True Then _
            exam2 = Val(exam2TextBox.Text) * EXAM2WV
        total += exam2

        If finalCheckBox.Checked = True Then _
            finalProject = Val(finalTextBox.Text) * FINALWV
        total += finalProject

        totalWv = LAB2WV + LAB3WV + LAB4WV + LAB5WV + EXAM1WV + EXAM2WV + FINALWV
        endTotal = total / totalWv
        percentageLabel.Text = String.Format("{0:P}", endTotal)








    End Sub
End Class

Attached Images
 

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>