![]() In this tutorial you have learned about If Statements, If Else Statements and Nested If Else statements. Then the If Statements condition is, “Is A greater than 100 AND less than 150?” If it is, it will continue to execute the If Statement otherwise it will terminate. The only difference with this example is we are using the random class to generate a random number between 90 – 160, which is assigned to the variable A. Not Operator – If the condition is false, then the result will be true, or vice versa.Įxample of Logical And Operator Dim a As IntegerĬonsole.WriteLine("A is greater than 100, but less than 150, A = " + a.ToString()) Or Operator – If either of the conditions are true, the result will be true You can use the logical operators to extend the If Else Statements and use two conditions, for example if a = b And a > 19 Then OperatorĪnd Operator – If both conditions are true, then the result is true If Else Statements can become quite long, so it is best to use a Select Case Statement which will be addressed in the next lesson. The If Else Statement will see if the statements are true: if they are it will print out the correct message, and if they are false it will print the last message. However, we have made a new string variable called “message” this was made to avoid repeating the console message. The process is the same as before, but we have more decisions. #IF THEN STATEMENTS IN VISUAL BASIC FOR EXCEL PASSWORD#If username = "Admin" And password = 2012 ThenĬonsole.WriteLine("Oops could not find you!") If username = "Dave" And password = 12345 Then You can also have a nested If Else Statement. You are also using the logical operator And which will be explained later. So if username = “Asim” AND password = 243, then “Welcome Asim” is displayed otherwise “Access Denied” is displayed. Then we compare those values to the values in our If Statement. You have two variables (string/integer) which we use to store the values the user enters when prompted. This is similar to the above If Statement. If username = "Asim" And password = 243 Then Comment out the other If Statement ( CTRL+K+C) and copy the following code: Dim username As String ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |