If the condition returns a boolean true, then the set of actions defined under the if block will be executed but if the conditional expression returns a boolean false then the statements under the else block will be executed. The output from the above code will be a msgbox as shown below and whether the condition is true or false “Result Published” will be printed in the immediate window. Note: To execute the code, click on F5 or hit the run button on the toolbar. MsgBox "Student obtained a perfect score" In the VB editor, click on Insert -> Module.ĭim Obtained_Marks, Total_Marks As Integer Note: To write VB Code Open Microsoft Excel (supported version Excel 2007,2010, 2013, 2016, 2019), navigate to Developer Tab -> Visual Basic (Alternatively use shortcut Alt+F11). The program directly goes to the line after the End If statement. Hence the if block statements are skipped and are never executed. If the condition returns true then a set of activities defined under the if block is executed, but if the condition returns false then the program will not enter the if block. Once the code enters the conditional statement, the expression is verified. Statements: This set of actions will be performed if the condition is true. If the condition is Null then it is treated as False. If the result is true then the statements in the If block will be executed. Based on the Boolean result of this condition the action will be performed. If the condition evaluates to true then the code mentioned in the If block will be executed.Ĭondition: This is the required field. If statements execute a set of actions depending on the condition. Placing an If statement inside another if statement.Įach case statement will have a variable value,īased on the selection value mentioned in the select case statement, appropriate case will be executed. If the condition is true otherwise statements under elseĮach Else block if again have a conditional statementīased on which the statements will be executed. Set of statements under If block are executed Set of statements are executed only if the condition is true.
0 Comments
Leave a Reply. |