Find more freelance jobs
|
Using Sub and Function Procedures in Code
When you call a Function in your code, you do like this:
name = findname()
Here you call a Function called "findname", the Function returns a value that will be stored in the variable "name". Or, you can do like this: msgbox "Your name is " & findname() Here you also call a Function called "findname", the Function returns a value that will be displayed in the message box. When you call a Sub procedure you can just type the name of the procedure. You can use the Call statement, like this: Call MyProc(argument) Or, you can omit the call statement, like this: MyProc argument Conditional Statements Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. In VBScript we have two conditional statements: · If...Then...Else statement - use this statement if you want to select one of two sets of lines to execute · Select Case statement - use this statement if you want to select one of many sets of lines to execute If....then.....else You should use the IF statement if you want to execute some code if a condition is true, or if you want to select one of two blocks of code to execute. If you want to execute only one statement when a condition is true, use this syntax for the if...then...else statement, like this: If i = 10 Then msgbox "Hello" Notice that there is no ..else.. in this syntax. You just tell the code to perform one action if the condition (i) is equal to some value (in this case the value is 10). If you want to execute more than one statement when a condition is true, use this syntax for the if...then...else statement, like this: |