Find more freelance jobs
|
If i = 10 Then msgbox "Hello" i = 11 more statements End If There is no ..else.. in this syntax either. You just tell the code to perform multiple actions if the condition (i) is equal to some value (in this case the value is 10). If you want to execute some statements if a condition is true and execute others if a condition is false, use this syntax for the if...then...else statement, like this: If i = 10 Then msgbox "Hello" i = 11 Else msgbox "Goodbye" End If The first block of code will be executed if the condition is true (if i is equal to 10), the other block will be executed if the condition is false (if i is not equal to 10). Select case You should use the SELECT statement if you want to select one of many blocks of code to execute. Select Case payment Case "Cash" msgbox "You are going to pay cash" Case "Visa" msgbox "You are going to pay with visa" Case Else msgbox "Unknown method of payment" End Select This is how it works: First we have a single expression (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each Case in the structure. If there is a match, the block of code associated with that Case is executed. Looping Statements Very often when you write code, you want allow the same block of code to run a number of times. You can use looping statements in your code to do this. In VBScript we have four looping statements: · Do...Loop statement - loops while or until a condition is true · While...Wend statement - use Do...Loop instead · For...Next statement - run statements a specified number of times. · For Each...Next statement - run statements for each item in a collection or each element of an array Do...Loop |