Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test For 3 Conditions

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I am retrieving the different categories & their corresponding amounts which make up a salary package of all the employees of a firm from SQL Server. Some of the categories are his Basic Salary, HRA, Medical, how much house rent he pays etc...Now what I want to do is for each employee get the house rent he pays & if it is greater than 2000, then it should be subjected to 3 conditions. How do I do this? Note that the result generated from all the 3 conditions will always be a number & the condition that generates the least amount, that amount will be finally displayed to the users in a web page.

Thanks,

Arpan
 
If HouseRent >= 2000 then
If HouseRent Condition1 then
intReturn1 = ConditionValue
End If
If HouseRent Condition2 then
intReturn2 = ConditionValue
End If
If HouseRent Condition3 then
intReturn3 = ConditionValue
End If

If intReturn1 < intReturn2 and intReturn1 < intReturn3 then
'intReturn1 is the least
response.write intReturn1
ElseIf intreturn2 < intReturn1 and intreturn2 < intReturn3 then
'intReturn2 is the least
response.write intReturn2
ElseIf intreturn3 < intReturn1 and intreturn3 < intReturn2 then
'intReturn3 is the least
response.write intReturn3
End If
end if

This should do it using a bunch of If statements... Not sure if this is the best way though...mwa
 
Hi MWA,

Thanks for your response. Actually what I want is this:

If the employee pays house rent, then it should subjected to the following 3 conditions:

1. The amount of HRA he pays per month.
2. (House Rent He Pays)-(10% Of His Basic Salary).
3. If he stays in Texas, New York, Chicago or Ohio, 50% of his basic salary else 40% of his basic salary (i.e. if he doesn't reside in any of the 4 cities given above then 40%).

The condition that generates the least amount out of the 3 conditions given above should finally be displayed to the users in a web page. Now how do I go about it? What I am not understanding is what If condition do I use for generating the 3 amounts.

Thanks once again for your help,

Regards,

Arpan
 
I would agree mostly, though it could be shortened by the following manner:
Code:
If HouseRent >= 2000 then
     checkAmt = -1
     If HouseRent Condition1 then
          intReturn1 = ConditionValue
          checkAmt = intReturn1
     End If
     If HouseRent Condition2 then
          intReturn2 = ConditionValue
          If checkAmt = -1 OR checkAmt > intReturn2 Then checkAmt = intReturn2
     End If
     If HouseRent Condition3 then
          intReturn3 = ConditionValue
          If checkAmt = -1 OR checkAmt > intReturn3 Then checkAmt = intReturn3
     End If

     Response.Write checkAmt
end if

This will speed it up a litte, it is basically the same code the mwa posted with the only change being that it is checking for the smallest existing intReturn while it is in the first set of if stmts.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Were you able to figure this out using our examples?

mwa
 
Yeah, I could very well figure out what you were trying to explain. Actually what I have thought is first collect the amounts generated by the 3 conditions in 3 different variables, say, iAmt1, iAmt2 & iAmt3 & then invoke the following function to get the least amount:

<%
Function Min(ByVal x1,ByVal x2)
'this will return the minimum of any 2 amounts

Min=x1
If(x2<Min)
Then Min=x2
End Function

Dim iAmt1,iAmt2,iAmt3,iMinAmount

'& this will invoke the above function to get the minimum
'of the 3 amounts

iMinAmount=Min(Min(iAmt1,iAmt2),iAmt3)
%>

though I haven't implemented the above yet!!!

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top