If Then Else NOT WORKING

# Thread: If Then Else NOT WORKING

1. Senior Member
Join Date
Dec 1969
Posts
209

## If Then Else NOT WORKING

I have been working on this for a day now and I am stumped. It does exactly what I don&#039;t want it to do (just the opposite). <BR><BR>What I want to happen is to assign bCriteriaMet2 = true if this criteria is met otherwise set bCriteriaMet2 = false. <BR><BR>_____<BR><BR>** What I want to happen<BR>If ((nExemptStatus = 1) and (dtDaySelectedMonth &#060;= dtDatePlusThreeMonths) and (cdbl(nVacAvail) + cdbl(nSickAvail) &#060;&#062; 0)) Then<BR><BR>bCriteriaMet2 = true<BR>Else<BR>bCriteriaMet2 = false<BR>End If <BR>____<BR><BR>** This works but does the opposite<BR>If ((nExemptStatus = 1) and (dtDaySelectedMonth &#060;= dtDatePlusThreeMonths) and (Not cdbl(nVacAvail) + cdbl(nSickAvail) &#060;&#062; 0)) Then <BR>bCriteriaMet2 = false<BR>Else<BR>bCriteriaMet2 = true<BR>End If <BR>____<BR><BR>What is happening in scenario 2 is bCriteriaMet2 is equal to true when cdbl(nVacAvail) + cdbl(nSickAvail) = 0) and what I want ist bCriteriaMet2 to be equal to true when cdbl(nVacAvail) + cdbl(nSickAvail) &#060;&#062; 0)<BR><BR>Any help would be greatly appreciated.<BR><BR>Thanks.<BR><BR> Ben Smith

2. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: If Then Else NOT WORKING

make sure your criteria are evaluating the way you think they are - i.e. Response.Write the result outside the if/else to make sure.

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## ''NOT'' is not working...

...or at least not the way you think it is.<BR><BR>NOT has the HIGHEST PRIORITY of all operators (along with = and negation). See here:<BR><BR>http://msdn.microsoft.com/library/en-us/script56/html/vsgrpoperatorprecedence.asp<BR><BR>So you are doing, effectively,<BR> and ([hl="yellow"]( Not cdbl(nVacAvail) )[/hl] + cdbl(nSickAvail) &#060;&#062; 0)) Then <BR><BR>Which means you are getting a FALSE value from NOT if nVacAvail is non-zero (TRUE value if it is zero). Then that, in turn, has to be converted back to a number: -1 for TRUE and zero for false.<BR><BR>WHY would you do that instead of the much simpler:<BR><BR> ... and (cdbl(nVacAvail) + cdbl(nSickAvail)[hl="yellow"] = [/hl]0)) Then <BR><BR>Incidentally, this characteristic of the NOT operator is pretty much universal in computer languages, whatever the actual "name" of the operator is.<BR><BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•