Page 199 - DCAP408_WEB_PROGRAMMING
P. 199

Unit 7: Introduction to ASP (Active Server Pages)




          The If...Then Statement                                                               Notes

          The simplest technique used to validate a condition is to check whether it is true. This can be
          done using an If...Then statement. The formula to use is:
          If ConditionToCheck is True Then Statement

          The program examines a condition, in this case ConditionToCheck. This ConditionToCheck can
          be a simple expression or a combination of expressions. If the ConditionToCheck is true, then
          the program will execute the Statement.
          There are two  ways you can use the If...Then statement. If  the conditional formula is  short
          enough, you can write it on one line, like this:

          If ConditionToCheck is True Then Statement
          If there are many statements to execute as a truthful result of the condition, you should write the
          statements on alternate lines. Of course, you can use this technique even if the condition you are
          examining is short.




             Notes  In this case, one very important rule to keep is to terminate the conditional statement
             with End If.

          The formula used is:
          If ConditionToCheck is True Then
              Statement
          End If

          The If...Then...Else Statement

          The If...Then statement offers only one alternative: to act if the condition is true. Whenever you
          would like to apply an alternative in case the condition is false, you can use theIf...Then...Else
          statement. The formula of this statement is:

          If ConditionToCheck is True Then
              Statement1
          Else
              Statement2

          End If
          When  this  section  of  code  executes,  if  the  ConditionToCheck  is  true,  then  the  first
          statement,Statement1, is executed. If the  ConditionToCheck is false, the second statement, in
          this
          caseStatement2, is executed.
          The If...Then...ElseIf Statement

          The If...Then...ElseIf statement acts like the If...Then...Else expression, except that  it offers as
          many choices as necessary. The formula to use is:
          If Condition1 is True Then





                                           LOVELY PROFESSIONAL UNIVERSITY                                   193
   194   195   196   197   198   199   200   201   202   203   204