Click here to Skip to main content
15,868,306 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hey everyone i'm currently working a question and i'm having trouble on the final part where i have to add the sum of all scores and in the specific category it doesnt seems to be showing either pass or fail when the values are entered, any tips or improvements that i could make would be greatly appreciated

image of my question is here : http://imgur.com/pw9XsyY

sorry about my ugly and awful code

thanks!


VB
Private Sub BtnPF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPF.Click
        Dim Mynum1 As Integer
        Dim Mynum2 As Integer
        Dim Mynum3 As Integer
        
       
        If Not IsNumeric(TxtboxS1.Text & TxtboxS2.Text & TxtboxS3.Text) Then

            MessageBox.Show("Data not valid")

        End If



        If (IsNumeric(TxtboxS1.Text) = True) Then
            Mynum1 = CInt(TxtboxS1.Text)

           
            If (Mynum1 < 5 AndAlso Mynum2 < 5) Then
                LblStatusBox.Text = "Fail"

                If (IsNumeric(TxtboxS2.Text) = True) Then
                    Mynum2 = CInt(TxtboxS2.Text)

                    If (Mynum2 < 5 AndAlso Mynum3 < 5) Then
                        LblStatusBox.Text = "Fail"

                        If (IsNumeric(TxtboxS3.Text) = True) Then
                            Mynum3 = CInt(TxtboxS3.Text)

                            If (Mynum3 < 5 AndAlso Mynum3 < 5) Then
                                LblStatusBox.Text = "Fail"

                            End If



If (Mynum1 + Mynum2 + Mynum3 > 10) And TxtboxCat.Text = "A" Then
     
       LblStatusBox.Text = "Pass"

If (Mynum1 + Mynum2 + Mynum3 > 15) And TxtboxCat.Text = "B" Then

       LblStatusBox.Text = "Pass"


If (Mynum1 + Mynum2 + Mynum3 > 18) And TxtboxCat.Text = "C" Then

      LblStatusBox.Text = "Pass"



Else
           
LblStatusBox.Text = "Fail"








          End If
          End If

          End If
          End If
          End If
          End If
          End If
          End If
Posted
Updated 22-Mar-15 3:50am
v4
Comments
Richard MacCutchan 22-Mar-15 10:02am    
You are testing the values of some variables before you have created them. You should collect all your input variables before you try comparing them against limits.

1 solution

You should make one boolean variable hasPassed=False.
Then as parse all TextBox.Text to Integers.

Following your logic, everything above here is superfluous. Use the boolean variable instead

VB
If (Mynum1 + Mynum2 + Mynum3 > 10) And TxtboxCat.Text = "A" Then

       hasPassed = true;

If (Mynum1 + Mynum2 + Mynum3 > 15) And TxtboxCat.Text = "B" Then

       hasPassed = true;


If (Mynum1 + Mynum2 + Mynum3 > 18) And TxtboxCat.Text = "C" Then

      hasPassed = true;


Then set the label based on the result.
 
Share this answer
 

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