Home | » | ASP | » | VBScript Branching Logic |
There are two kings of branching logic controls: subroutines and functions. Subroutines perform actions. Functions compute values.
Branching logic is often used for code that is repeated throughout a script or may need to be changed often. Putting it into a function or subroutine can improve readability, shorten the length of your code, and make it easier to maintain and improve.
Using Subroutines
The Subroutines are also Called as Procedure those are used for Performing Some Actions these are Just Like a Function But a Procedure Doesn't Return a Value as Like a Procedure and For Calling a Procedure there is no need to put an open Bracket as Function takes When we Calls a sub Routines then the Body of the Procedure is Executed one by one and after Executing all the statements of Procedure this will comes back to the program For Executing another or Remaining Part of the Program For Making a Procedure We have to use sub Keyword with the name of Procedure Like This.
Sub Active
Response.write "Hello Procedures"
End Sub
This is simple Definition of Procedure and now if you wants to Call a Sub Procedure then just use the name of the Procedure When you will use the name of Procedure then Body of Procedure will Executed and all the Statements those are Contained in Sub Procedure are Executed.
You Can Also Pass Some Arguments to the Procedure like Some Variables as we Pass Some Arguments to the Functions For Passing a Arguments A Sub Procedure must be Capable of Accepting a Argument and you must have to define a Procedure with Arguments like this
Sub Active(num)
Response.write "you Passed " & num
End Sub
When we wants to Call a Prcedure then you must have to supply some Arguments like this Active 4. Now this will Print 4 as Output that is passed to Procedure as Argument
Example: 12 Using Subroutines
Using Functions
Functions are Also Used for Storing a Code that can be Called any time and anywhere whenever a Code that is Repeated many times then that code must be placed into the Function and The Main Difference b/w procedure and a Functions is that a Procedure never Return a Value to Program but a Functions is that which Return Some Values when they are called to the Calling Program and a Functions We can Add A Function to Some Expression For Strong the value that will be Returned by Function and one can also Pass Wome Arguments to a Function as Like Procedures.
Example: 13 Using Functions
Blogger Comment
Facebook Comment