“If…Then...Else” statement:
- The “If…Then...Else” statement is used to run the particular block of statements, based on the value of the condition.
- The “If” statement can be followed by an “Else” statement that executes when the Boolean expression is “false”.
Syntax:
Consider the syntax for the “If...Then...Else” statement is as follows:
If condition Then
'statement
Else
'statement
End If
Here, if the “condition” is a Boolean condition is “true”, then it executes the “If” block other it executes “Else” block.
Explanation of Solution
2.
Given statement:
'assign the value to the variable
intX = 100
'check "intX" value is less than or equal to 1
If intX <= 1 Then
'assign the value to the variable
intY = 99
'else statement
Else
'assign the value to the variable
intY = 0
'end the statement
EndIf
Explanation:
- Here, the “intX” variable is assigned with the value “100”.
- Check the value of “intX” is less than or equal to “1” or not...
Explanation of Solution
3.
Given statement:
'assign the value to the variable
intX = 0
'check "intX" value is not equal to 1
If intX <> 1 Then
'assign the value to the variable
intY = 99
'else statement
Else
'assign the value to the variable
intY = 0
'end the statement
EndIf
Explanation:
- Here, the “intX” variable is assigned with the value “0”.
- Check the value of “intX” is not equal “1” or not.
- If the condition is “true”, assign the value “99” to the variable “intY”...
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out With Visual Basic (8th Edition)
- An expression can contain arithmetic, comparison, and logical operators. Indicate the order of precedence for the three types of operators by placing a number (1, 2, or 3) on the line to the left of the operator type. __________ Arithmetic __________ Logical __________ Comparisonarrow_forwardWrite an If....Then decision structure to compare the two numbers in the following variables: decDeveloperPay and decWebDesignerPay. Display a message box that states decDeveloperPay is greater than decWebDesignerPay. Write an If statement that displays the message box "Today was a good day" if the value in the variable intTemp is within the range from 30 to 35. this is for Visual Basic 2015arrow_forwardThe dblBonus variable contains the number 1234.75. Write the assignment statement to display the value with a dollar sign, a thousands separator, and no decimal places in the lblBonus control.arrow_forward
- If the intTotalScore and intTests variables contain the numbers 200 and 0,respectively, the statement dblAvg = intTotalScore / intTests will_________ .a. assign 0 to the dblAvg variable b. result in a syntax error c. result in a logic error d. result in a run time errorarrow_forwardWrite a statement that displays the following numeric variables in amessage box. grandTotalarrow_forwardWhen an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period:d =1/2 gt2The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time in seconds that the object has been falling. Create an application that allows the user to enter the amount of time that an object has fallen and then displays the distance that the object fell. The application should have a method named FallingDistance. The FallingDistance method should accept an object’s falling time (in seconds) as an argument. The method should return the distance in meters that the object has fallen during that time interval.arrow_forward
- The user should be able to test different monthly deposit amounts, interest rates, and lengths oftime to see how increases and decreases impact their investment growth.4. Your code will need to account for the following:a. Month: The number of months based on user input in the “Number of Years” fieldb. Opening Amount: The initial investment amount as well as the opening balance eachmonth, which includes interestc. Deposited Amount: The dollar amount the user plans to deposit each month. This valuewill be the same every month for the duration of the investment.d. Total: The sum of the opening and deposited amountse. Interest: Money earned based on the “annual interest” rate input by the user. Theinterest based on an opening amount of $1 and a deposited amount of $50 with aninterest rate of 5% compounded monthly is:(Opening Amount + Deposited Amount) * ((Interest Rate/100)/12)OR(1 + 50) * ((5/100)/12)Note: Dividing by 100 converts the interest rate percentage to a decimal.Note: 12 is the…arrow_forwardThis code needs to be written in C#: If the user guesses the number in 3rd try you will assign:Points = (10 – 3)^2/100 = 7 ^ 2 = 49 points.When the user presses the ‘Start Game’ button, the game will start. User will enter a number in the largetextbox and press Submit. If number is correct display the Messagebox, else continue with game. Also tellthe user if the number entered was higher or lower than actual number.The problem flow will be as follows:1. Player enters name and number of chances2. Player presses Start game3. Computer generates a secret random number4. Player enters choice5. Program checks if number matches guesses number. If number matches jump to step #106. Program updates message whether the guessed number is more or less than actual7. Program reduces available chances by 1 and display messages on changes8. If chances become 0 stop game and tell use Game has ended, and she will have to press ‘Start Game’again. Same message should be spoken by the program using text to…arrow_forwardArea Calculator: Prompt the user to enter two choices 1 or 2. If user enters 1 then ask him for length of side of square and if user enters 2 then prompt for length and breadth of rectangle. In both case the output should be the area of square (case 1) or rectangle (case2). In C++arrow_forward
- Scientists measure an object’s mass in kilograms and its weight in Newtons. If you know the amount of mass of an object, you can calculate its weight, in Newtons, with the following formula: Weight = Mass × 9.8Create an application that lets the user enter an object’s mass and then calculates its weight. If the object weighs more than 1000 Newtons, display a message indicating that it is too heavy. If the object weighs less than 10 Newtons, display a message indicating that it is too light.arrow_forwardIf the intTotalScore and intTests variables contain the numbers 0 and 2,respectively, the statement dblAvg = intTotalScore / intTests will___________ . a. assign 0 to the dblAvg variable b. result in a syntax error c. result in a logic errord. result in a run time errorarrow_forwardView the code and add the following: This is also inside the code to show you where it must be added. % use an if/else statement to check to see if the ball is moving % down (negative). If it is, then drag has an opposite sign % as gravity in the acceleration formula. Otherwise gravity % and drag have the same sign. Calculated the acceleration % in the y direction inside the if/else statement. % Now calculate the acceleration in the x . % ******************************************************* % ***************************************************** % calculate the new velocity at the end of the time step % this will have X and Y components, so you need a variable % for each. One is velFinalX and the other is velFinalY. % ******************************************************* % ****************************************************** % Get a new velocity vector and angle given the X and Y % The velocity is the variable "vel" and angle is "angle"…arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning