0

I want to make a program that "Loan will be accepted if Earns over 30k & on the job for more than 2 years or been on the job for more than 5 years. and age between 30 - 50.

But doesn't working

If sngSalary > 30000 Then
    If sngAge < 50 Then
        If sngYear > 5 Then
            lblMessage.Text = "Application qualifies"
        Else
            lblMessage.Text = "Application does not qualifies"
        End If
    Else
         If sngYear >= 2 Then
            lblMessage.Text = "Application qualifies"
         Else
            lblMessage.Text = "Application does not qualifies"
         End If
    End If
Else
    If sngAge > 30 Then
         If sngYear > 5 Then
             lblMessage.Text = "Application qualifies"
         Else
             lblMessage.Text = "Application does not qualifies"
         End If
    Else
         If sngYear >= 2 Then
             lblMessage.Text = "Application qualifies"
         Else
             lblMessage.Text = "Application does not qualifies"
         End If
    End If
End If

2 Answers 2

1

Just code it up almost exactly like you said in your description:

Private Sub Test()
   If (sngSalary > 30000 And sngYear > 2) Or (sngYear > 5 And sngAge >= 30 And sngAge <= 50) Then
      lblMessage.Text = "Application qualifies"
   Else
      lblMessage.Text = "Application does not qualifies"
   End If
End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

Quite often complex logic can be simplified by moving the code to a function and revising the logic so that the function is left early if a criteria is not met. In writing such a function I try to keep the logic retricted to simple yes/no gates.

The expression of the required conditions by the OP is quite confused so the code below may not be correct, but it does demonstrate the principle.

Option Explicit

Public Function IsEligible(ByVal ipSalary As Long, ByVal ipAge As Long, ByVal ipEmploymentTime As Long) As String

    IsEligible = "Application does not qualify"
    If ipEmployment < 2 Then Exit Function
    
    If ipSalary < 30000
    
        If ipEmploymentTime < 5 Then Exit Function
        If ipAge < 30 Then Exit Function
        If ipAge > 50 Then Exit Function
    
    End If
    
    IsEligible = "Application qualifies"
    
End Function

2 Comments

I like this idea and use it often in my code. One thought: I would expect the function to return a Boolean based upon it's name.
@BrianMStafford You are of course correct. I changed my mind halfway through writing and didn't update the function signature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.