Free NT Web Hosting, Free ASP Hosting, Free Web hosting, Free Hosting - DomainDLX
    

    Home
    Registration
    FAQs
    Terms of service
    Contact us

    Learn ASP
    Databases
    Articles

To control whether or not a part of the script should run can be done by an IF block or a SELECT block.  The IF block is the simplest way.  The If keyword will test a rule, if it returns true then it will run that part of the script between the If and End If keywords.  My last sentence actually had an "if" concept, like this:

If A = 1 Then
    'Run This
    'only if A = 1
End If

If the rule returns false, it can either not run that part of the script or run a different part:

If A = 1 Then
    'Run This
   'only if A = 1
Else
   'Run This
   'only if A did not = 1
End If

If the rule was false you can also give other rules, only if the main rule was false and if all other rules are false then run a final part of code:

If A = 1 Then
    'Run This
    'only if A = 1
ElseIf B = 1 Then
    'Run This
    'only if B = 1, and A did not = 1
ElseIf A = 2 Then
    'Run This
    'only if A = 2, A did not = 1, and B did not = 1
Else
   'Run This
   'only if A did not = 1 or 2, and B did not = 1
End If

Simple, sometimes, but if you get into many ElseIfs where the rule uses the same variable, then a SELECT block is a good idea.  SELECT will run a set of tests on the same variable and run a bit of code for the tests that are true.  To specify a test you use the CASE command.  If all tests (CASE commands) are false, it can continue without running the code from any rules or run a code when all rules come back false.  This is marked with CASE ELSE.  The end of the a SELECT block is END SELECT. 

Example:

Select VariableA
Case 5
    'Run if
VariableA = 5
Case < 2
    'Run if
VariableA < 2
Case Else
    'Run if other rules didn't apply
End Select

By: Matthew Holder