Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
net
A control structure is a programming structure that allows your program to make decisions. Types of controls
Conditional logic allows you to match condition if condition matches then result come if condition not matches result not come
Example
In job selection form if age is less then 27 then you fill form or if age is more then 27 then you are not eligible for this job.
Dim Result
Dim Result if Result >= 75 then label1.text="Grade A " elseif Result >= 60 then label1.text="Grade B " elseif Result >= 45 then label1.text="Grade C " else label1.text="Failed " end if
Dim Result
if Result >= 75 then if Result >= 65 then if Result >= 55 then if Result >= 45 then if Result <= 35 then
label1.text("Grade A ") label1.text("Grade b") label1.text("Grade c ") label1.text("Grade d ") label1.text("Grade fail ")
select case flower case "rose" label1.text(flower & " costs 20rs") case "daisy" label1.text(flower & " costs 15rs") case "orchild" label1.text(flower & " costs 12rs") case else label1.text("There is no such flower in our shop") end select
ASP performs several types of repetitive operations, called "looping". Loops are set of instructions used to repeat the same block of code till a specified condition returns false or true
<%@ language="vbscript" %> <% label1.text("<h1>Multiplication table</h1>") label1.text("<table border=2 width=50%") For i = 1 to 9 'this is the outer loop label1.text("<tr>") label1.text("<td>" & i & "</td>") For j = 2 to 9 'inner loop label1.text("<td>" & i * j & "</td>") Next label1.text("</tr>") Next label1.text("</table>") %>
<% Dim i i=0 Do While i<=10 response. write( i & "<br>") i=i+1 Loop %>
<% StartVal=1 Do while StartVal < 11 label1.text "This is loop " & StartVal & "<br>" StartVal=StartVal+1 Loop %>
<% StartVal=1 Do until StartVal = 11 label1.text "This is loop " & StartVal & "<br>" StartVal=StartVal+1 Loop %>
<% StartVal=1 Do until StartVal = 11 If StartVal < 6 then label1.text "This is loop " & StartVal & "<br>" StartVal=StartVal+1 Else Exit Do End If Loop %>
Functions and Sub procedures Functions and sub procedures have many similarities: They can be called or invoked from anywhere within your script. A function or sub procedure can be reused as many times as required, thus saving you time writing out repetitive code Both are blocks of self contained code that can accept arguments. Both will only run when called or invoked from code elsewhere and will not run automatically when the page is loaded.
The difference between a function and a sub is that a sub will do some stuff (like printing something to the screen) and then quit,
while a function runs some code and then returns the result back to the code that called it. A Function could be used to do a calculation and then return a result.
<% Sub NameOfSubRoutine(parameter1, parameter2) 'code goes here... End Sub %>
<% Function NameOfFunction(parameter1, parameter2) 'code goes here NameOfFunction = "return value" End Function %>
<% Sub PrintOut(name,address,country) label1.text name label1.text address label1.text country End Sub %>